您必须在中更改顺序$wp_query->posts
. 将其与get_option( \'sticky_posts\' )
.
示例:
function move_stickies_down( $num = 1 )
{
global $wp_query;
if ( empty ( $wp_query->posts ) )
return;
$stickies = get_option( \'sticky_posts\' );
if ( empty ( $stickies ) )
return;
$sticky_posts = $top = $after = array();
foreach ( $wp_query->posts as $p )
{
if ( in_array( $p->ID, $stickies ) )
{
$sticky_posts[] = $p;
}
elseif ( $num > 0 )
{
$top[] = $p;
$num -= 1;
}
else
{
$after[] = $p;
}
}
$wp_query->posts = array_merge( $top, $sticky_posts, $after );
}
将此函数添加到
functions.php
在循环之前调用它,如下所示:
move_stickies_down( 2 );
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
// show post
}
}