自定义类别模板显示所有类别

问题描述:

以下是模板。我的类别slug是'新闻',类别ID是40.我标题为php文件类别 - news.php和category-40.php。这两个文件都提供了正确的模板,但是当我需要的是单个类别时,它将显示所有类别。为了显示单个类别,我需要更改什么?自定义类别模板显示所有类别

<?php 
/* 
Template Name: Category PAGE 
*/ 
get_header();?> 

<?php 
    if (have_posts()) : while (have_posts()) : the_post(); 

    $blog_style = $hana_post_meta['blog_style']; 
    if($blog_style=='fluid') $hana_page_options['layout'] = 'full'; 
?> 
<div class="blog-container <?php echo $blog_style;?>-blog"> 

    <div id="content" class="<?php echo ($blog_style!='fluid')?vintage_content_class():'';?>"> 

     <?php 
     //query posts 
     $postsPerPage=hana_get_opt('_post_per_page_on_blog')==''?5:hana_get_opt('_post_per_page_on_blog'); 
     $excludeCat=explode(',',hana_get_opt('_exclude_cat_from_blog')); 
     query_posts(array(
      'category__not_in' => $excludeCat, 
      'paged' => get_query_var('paged'), 
      'posts_per_page' => hana_get_opt('_post_per_page_on_blog') 
     )); 

     $blog_loop = array(); 
     $blog_loop['layout'] = $hana_page_options['layout']; 
     $blog_loop['column'] = $hana_post_meta['blogcolumn']; 

     get_template_part('loop', $blog_style); 

     wp_reset_query();?> 

    </div> 

    <?php get_sidebar();?> 
    <?php vintage_get_addtional_products(); ?> 
</div><?php 

endwhile; endif;?>  

<?php get_footer(); ?> 
+0

最新的问题是什么? – 2013-02-28 18:53:12

+0

我必须更改哪些内容才能显示单个类别,而不是全部使用此模板? – user2120881 2013-02-28 18:58:31

query_posts()需要去The Loop之前。 See the Wordpress Function Reference for query_posts()