0

这是我找到并尝试使用的片段:

<?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 个类别 Watch 和 View,我也用帖子上的复选框检查了它们。

4

1 回答 1

0

解决了!将此添加到array

 'category__in'         => 'n'

其中n是您的类别的数量

于 2013-06-23T15:32:23.570 回答