我有一个自定义模板,它应该只显示特定类别的帖子。为了完成这项工作,我需要在代码内部更改什么?
if ( ! function_exists( \'attitude_theloop_for_template_blog_full_content_one\' ) ) :
/**
* Fuction to show the content of page template full content display.
*/
function attitude_theloop_for_template_blog_full_content_one() {
global $post;
global $wp_query, $paged;
if( get_query_var( \'paged\' ) ) {
$paged = get_query_var( \'paged\' );
}
elseif( get_query_var( \'page\' ) ) {
$paged = get_query_var( \'page\' );
}
else {
$paged = 1;
}
$blog_query = new WP_Query( array( \'post_type\' => \'post\', \'paged\' => $paged, \'cat\' => 1 ) );
$temp_query = $wp_query;
$wp_query = null;
$wp_query = $blog_query;
global $more; // Declare global $more (before the loop).
if( $blog_query->have_posts() ) {
while( $blog_query->have_posts() ) {
$blog_query->the_post();
do_action( \'attitude_before_post\' );
?>
<section id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<article>
<?php do_action( \'attitude_before_post_header\' ); ?>
<header class="entry-header">
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"><?php the_title(); ?></a>
</h2><!-- .entry-title -->
</header>
<?php do_action( \'attitude_after_post_header\' ); ?>
<?php do_action( \'attitude_before_post_content\' ); ?>
<div class="entry-content clearfix">
<?php
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content( __( \'Read more\', \'attitude\' ) );
wp_link_pages( array(
\'before\' => \'<div style="clear: both;"></div><div class="pagination clearfix">\'.__( \'Pages:\', \'attitude\' ),
\'after\' => \'</div>\',
\'link_before\' => \'<span>\',
\'link_after\' => \'</span>\',
\'pagelink\' => \'%\',
\'echo\' => 1
) );
?>
</div>
<?php do_action( \'attitude_after_post_content\' ); ?>
<?php do_action( \'attitude_before_post_meta\' ); ?>
<div class="entry-meta-bar clearfix">
<div class="entry-meta">
<span class="by-author"><?php _e( \'By\', \'attitude\' ); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( \'ID\' ) ); ?>"><?php the_author(); ?></a></span> |
<span class="date"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_time() ); ?>"><?php the_time( get_option( \'date_format\' ) ); ?></a></span> |
<?php if( has_category() ) { ?>
<span class="category"><?php the_category(\', \'); ?></span> |
<?php } ?>
<?php if ( comments_open() ) { ?>
<span class="comments"><?php comments_popup_link( __( \'No Comments\', \'attitude\' ), __( \'1 Comment\', \'attitude\' ), __( \'% Comments\', \'attitude\' ), \'\', __( \'Comments Off\', \'attitude\' ) ); ?></span> |
<?php } ?>
</div><!-- .entry-meta -->
</div>
<?php do_action( \'attitude_after_post_meta\' ); ?>
</article>
</section>
<?php
do_action( \'attitude_after_post\' );
}
if ( function_exists(\'wp_pagenavi\' ) ) {
wp_pagenavi();
}
else {
if ( $wp_query->max_num_pages > 1 ) {
?>
<ul class="default-wp-page clearfix">
<li class="previous"><?php next_posts_link( __( \'« Previous\', \'attitude\' ), $wp_query->max_num_pages ); ?></li>
<li class="next"><?php previous_posts_link( __( \'Next »\', \'attitude\' ), $wp_query->max_num_pages ); ?></li>
</ul>
<?php
}
}
}
else {
?>
<h1 class="entry-title"><?php _e( \'No Posts Found.\', \'attitude\' ); ?></h1>
<?php
}
$wp_query = $temp_query;
wp_reset_postdata();
}
endif;
此代码来自文件内容扩展名。php在library/structure文件夹中,im使用wordpress 3.6.1,态度不受主题限制。