簡體   English   中英

如何顯示所有帖子,但在wordpress上排除特定類別?

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

我現在有這段代碼,不管類別如何,都會吐出所有帖子。

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

除了排除類別為“博客”的帖子外,我該如何做?

您可以使用以下東西:-

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

要么

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

我找到了答案! 你必須更換

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

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