为什么这会带回最近的粘贴帖子而不管选择任何类别?

时间:2013-06-23 15:22:51

标签: php wordpress while-loop wordpress-theming

以下是我发现并尝试使用的代码段:

<?php
        $sticky = get_option( 'sticky_posts' );
        $most_recent_sticky_post = new WP_Query( array( 
            'post__in'            => $sticky, 
            'ignore_sticky_posts' => 1, 
            'orderby'             => date, 
            'posts_per_page'      => 1,
            'category'      => 'view'
        ) );
        ?>

        <?php while ( $most_recent_sticky_post->have_posts() ) :  $most_recent_sticky_post->the_post(); ?>
        <div class="imgFet">    
        <div > <?php the_post_thumbnail('homepage-thumb'); ?> </div>
        </div>
        <div class="textBoxcaption">        
            <div class="imgFeatureBoxImgText2">     
            <h2><?php the_title(); ?></h2>  
            <?php the_excerpt(); ?>
            <h3><a href=" <?php the_permalink(); ?>" > ReadMore</a></h3>
            </div>  
        </div>
    <?php endwhile; wp_reset_query(); ?>

我也尝试这样做,只是为每个类别带回粘性帖子:

<?php
            $sticky = get_option( 'sticky_posts' );
            rsort( $sticky );
            $sticky = array_slice( $sticky, 0, 1 );
            query_posts( array( 'post__in' => $sticky,'category' => 'watch','caller_get_posts' => 1 ) );
        ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="imgFet">    
        <div > <?php the_post_thumbnail('homepage-thumb'); ?> </div>
        </div>
        <div class="textBoxcaption">        
            <div class="imgFeatureBoxImgText2">     
            <h2><?php the_title(); ?></h2>  
            <?php the_excerpt(); ?>
            <h3><a href=" <?php the_permalink(); ?>" > ReadMore</a></h3>
            </div>  
        </div>
        <?php endwhile; ?>
    <?php wp_reset_query(); ?>

我有2个类别观看和查看,我也在帖子上勾选了复选框。

1 个答案:

答案 0 :(得分:0)

解决了!将其添加到array

 'category__in'         => 'n'

其中 n 是您的类别编号