为了账号安全,请及时绑定邮箱和手机立即绑定

如果没有缩略图,请忽略缩略图空间

如果没有缩略图,请忽略缩略图空间

PHP
翻阅古今 2022-09-25 20:28:14
因此,我有以下代码可以循环浏览我的帖子并以列表格式显示帖子。以下是我正在使用的代码:<?php while (have_posts()) : the_post(); ?>     <div class="one-sixth first"><?php the_post_thumbnail(); ?></div>     <div class="five-sixths"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div> <?php endwhile; ?>以下是带有缩略图的图像:这是当没有帖子缩略图可用时,它只会留下一个空白区域:
查看完整描述

1 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

如果选中缩略图(如果已显示),则显示占位符图像。希望这对你有帮助。


<?php

// Must be inside a loop.


if ( has_post_thumbnail() ) {

    the_post_thumbnail();

}

else {

    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) 

        . '/images/placeholder.jpg" />';

}

?>


查看完整回答
反对 回复 2022-09-25
  • 1 回答
  • 0 关注
  • 47 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信