0

我有一个排除类别(精选)的循环,所以现在我的类别在循环内不可见
现在这是我的问题,如果我将精选类别中的帖子设置为“粘性”,该帖子仍将显示在我的循环中。
我想要完成的是隐藏该类别的粘性帖子(精选),但允许我的其他帖子(来自其他类别)具有“粘性”。
我的循环:

<?php 
    $category = get_cat_ID('Featured');//Get our Featured Category     
    $args = array(           
    'category__not_in' => $category //Category is excluded 
                                   // but 'sticky' ones from Featured category
                                  // are still showing up...         
);

$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);

if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>

    <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

        <div class="entry"> 

            <?php the_content(__('Read more','my-domain')); ?>  

        </div><!--/entry-->
    </div><!--/post_class-->        
    <?php endwhile; ?>  
    <?php endif; ?><!--END if THE LOOP-->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>

任何想法我该如何解决这个问题?

4

1 回答 1

2

我没有可用的测试系统,但根据Codex,这样的东西应该可以工作:

$sticky = get_option( 'sticky_posts' );
$args = array(
    'category__not_in' => $category,
    'ignore_sticky_posts' => 1,
    'post__not_in' => $sticky
);
$query = new WP_Query( $args );
于 2013-09-29T13:32:58.377 回答