简体   繁体   中英

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' ) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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