3
我正在剪裁我的WordPress主题,我想在我的WordPress主页顶部添加最新的2个贴子。对于我使用下面的代码:在WordPress主页上显示最新的2个贴子
<div class="trending-right">
<?php
$sticky = get_option('sticky_posts'); // Get all sticky posts
rsort($sticky); // Sort the stickies, latest first
$sticky = array_slice($sticky, 0, 2); // Number of stickies to show
query_posts(array('post__in' => $sticky, 'caller_get_posts' => 1)); // The query
if (have_posts()) { while (have_posts()) : the_post(); ?>
<div class="trend-post">
<div class="thumb"><?php the_post_thumbnail(array(150,100)); ?></div>
<div class="title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
</div>
<?php endwhile;?>
<?php } else { echo ""; }?>
</div>
现在代码工作确定并显示最新的2篇置顶文章然而,它也将删除首页列出的所有其他职位,只显示那些2篇置顶文章。我试图用new WP_Query
替换query_posts
,但在这种情况下,它显示所有粘性帖子,而不是只显示2.
任何建议如何调整上面的代码,并使其工作?
是的,这正是我所需要的。非常感谢 –
不错的一个!完全没问题:) – McNab