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