如果我理解正确,您只想在首页显示最新的粘性帖子。一两个月前,我也遇到了同样的问题,并在WordPress Answers得到了社区的大力帮助。解决方案是在索引中运行两个循环。php文件。一个只拉最近的粘贴帖子,另一个显示所有其他类型的帖子。
这是link, 但我也会发布这个问题的代码。
<?php get_header(); ?>
<?php get_sidebar( \'left\' ); ?>
<?php if ( is_home() && !is_paged() ) : ?>
<div id="post-wrapper">
<?php
// Get IDs of sticky posts
$sticky = get_option( \'sticky_posts\' );
// first loop to display only my single,
// MOST RECENT sticky post
$most_recent_sticky_post = new WP_Query( array(
// Only sticky posts
\'post__in\' => $sticky,
// Treat them as sticky posts
\'ignore_sticky_posts\' => 1,
// Order by date to get the most recently published sticky post
\'orderby\' => date,
// Get only the one most recent
\'posts_per_page\' => 1
) );
?>
<?php while ( $most_recent_sticky_post->have_posts() ) : $most_recent_sticky_post->the_post(); ?>
<!-- your code to display most recent sticky -->
<?php endwhile; wp_reset_query(); ?>
<?php endif; ?>
<?php
$all_other_posts = array(
\'post__not_in\' => get_option( \'sticky_posts\' )
);
global $wp_query;
$merged_query_args = array_merge( $wp_query->query, $all_other_posts );
query_posts( $merged_query_args );
?>
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<!-- your code to display all other posts -->
<?php endwhile; ?>
<?php endif; ?>
</div> <!-- end #post-wrapper -->
显然,这段代码并不是对每个人都进行复制和粘贴。它在当时的代码结构中对我起作用。另外,请原谅这些讨厌的格式:P