你的category.php
应该有两个环-一个用于粘滞,一个用于常规帖子:
<?php
// get sticky posts array
$sticky = get_option(\'sticky_posts\');
// First WP_Query arguments
$args = array(
// include stickies
\'post__in\' => $sticky
);
$query = new WP_Query( $args );
// First loop for stickies only
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post() );
echo get_the_title() . \'<br />\';
echo get_the_content() . \'<br />\';
endwhile; endif;
wp_reset_postdata(); // don\'t forget to reset before the next loop
/***************************************/
// Second WP_Query arguments
$args = array(
// exclude stickies
\'post__not_in\' => $sticky
);
$query = new WP_Query( $args );
// Second loop for posts excluding stickies
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post() );
echo get_the_title() . \'<br />\';
echo get_the_content() . \'<br />\';
endwhile; endif;
wp_reset_postdata(); // if necessary
更有可能的是,您将需要更多
WP_Query
参数。
参见WP_Query;参见Sticky Posts