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

时间:2013-02-28 18:52:44

标签: php wordpress templates categories

这是模板。我的类别slug是'news',类别id是40.我把它命名为php文件category-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(); ?>

1 个答案:

答案 0 :(得分:0)

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