0
在WordPress中,我想显示2个最新帖子以及第一篇文章的帖子缩略图。如何在wordpress中显示最新帖子的图片
我一直在玩下面的代码,但是图像总是以第一篇文章以及第二篇文章的形式显示,当时我只想为第一篇文章展示图片。
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0
);
$post_args = array(
'numberposts' => 2,
'category' => $category->term_id
);
$posts = get_posts($post_args);
foreach($posts as $post) {
?>
<?php the_title(); ?>
<?php the_post_thumbnail('blog_post_image'); ?>
<?php
}
}
?>
我不是很好用PHP,我哪里会在上面的代码插槽此之前,请注意添加
$key
到foreach
,还有if
? – 2013-02-18 19:20:17@AdamScott替换你现有的'foreach'循环 – 2013-02-18 21:02:35