我在这里回显帖子缩略图:
echo \'<div class="post-image right">\' . the_post_thumbnail(\'featured-portrait-large\') . \'</div>\';
它可以工作,但它在div外部输出图像,如下所示:
<div class="post-header-text">
<img width="500" height="700" src="[IMAGE URL DELETED]" class="attachment-featured-portrait-large size-featured-portrait-large wp-post-image" alt="" loading="lazy">
<div class="post-image right"></div>
</div>
我想要的是:
<div class="post-header-text">
<div class="post-image right">
<img width="500" height="700" src="[IMAGE URL DELETED]" class="attachment-featured-portrait-large size-featured-portrait-large wp-post-image" alt="" loading="lazy">
</div>
</div>
有人能解释一下我为什么做错了什么吗?
最合适的回答,由SO网友:Sally CJ 整理而成
the_post_thumbnail()
回显输出,这就是缩略图放错位置的原因。
要手动回显输出,应使用get_the_post_thumbnail()
而是:
echo \'<div class="post-image right">\' . // wrapped
get_the_post_thumbnail(null, \'featured-portrait-large\') . \'</div>\';
或者您可以这样做:
echo \'<div class="post-image right">\';
the_post_thumbnail(\'featured-portrait-large\');
echo \'</div>\';