在任何页面中添加此功能:
get_template_part('recent', 'posts');
和
if(have_posts()){
while(have_posts()){ the_post(); ?>
<div class="site-content clearfix"><?php the_content(); ?></div>
<?php }
}
它正在工作,在我的页面上显示5篇博文。但它只有标题和发布日期。我想在这篇文章中添加缩略图。
我该怎么做?
答案 0 :(得分:0)
你可以在The Loop中添加这样的东西:
if( has_post_thumbnail() ) {
the_post_thumbnail();
}
您的帖子需要设置精选图片(以前称为后缩略图)。
<强>被修改强>
更深入的代码:
if( have_posts() ){
while( have_posts() ){
the_post();
if( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<div class="site-content clearfix"><?php the_content(); ?></div>
<?php
}
}
但请注意,如果帖子没有特色图片集,则the_post_thumbnail()
将不会被调用。