【问题标题】:How do I show all posts but exclude a specific category on wordpress?如何在 wordpress 上显示所有帖子但排除特定类别?
【发布时间】:2014-07-25 01:43:46
【问题描述】:

我有这段代码,现在无论类别如何,都会吐出所有帖子。

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

除了排除具有“博客”类别的帖子之外,我该如何做同样的事情?

【问题讨论】:

    标签: php wordpress categories templating


    【解决方案1】:

    你可以使用下面的东西:-

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 提示:切勿使用query_posts 进行自定义查询。它改变了主查询并中断了分页。你应该改用WP_Query
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多