如何显示所有帖子但排除wordpress上的特定类别?

时间:2014-07-25 01:43:46

标签: php wordpress categories templating

我有这个代码,现在不管类别如何都会吐出所有帖子。

<?php /* Start the Loop */ ?>
<?php global $query_string;
    query_posts( $query_string . '&ignore_sticky_posts=1' ); ?>

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

        <?php get_template_part( 'content', get_post_format() ); ?>

    <?php endwhile; // end of the loop. ?>
<?php wp_reset_query(); // reset the query ?>

我如何做同样的事情,除了排除有类别&#39;博客的帖子?

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容: -

$query = new WP_Query( 'cat=-12,-34,-56' );

OR

$query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );

答案 1 :(得分:0)

我找到了答案!你必须做替换

query_posts( $query_string . '&ignore_sticky_posts=1' );

query_posts( $query_string . '&ignore_sticky_posts=1&cat=-' . get_cat_ID( 'Blogs' ) );