简体   繁体   English

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

[英]How do I show all posts but exclude a specific category on wordpress?

I have this code that right now spits out all the posts regardless of category. 我现在有这段代码,不管类别如何,都会吐出所有帖子。

<?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 ?>

How Do I do the same thing, except exclude posts with a category 'blog'? 除了排除类别为“博客”的帖子外,我该如何做?

You can use below thing :- 您可以使用以下东西:-

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

OR 要么

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

I found the answer! 我找到了答案! You had to do replace 你必须更换

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

with

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM