以下代码:PHP:不能在 “标题” 插入 'the_title()' & “ALT” 属性在 'the_post_thumbnail'(WordPress的)
<?php if (has_post_thumbnail()) : ?>
<?php $attr = 'Is ' . the_title() . ' a good computer?'; ?>
<p><?php the_post_thumbnail('medium', ['title' => $attr, 'alt' => $attr]); ?></p>
<?php endif; ?>
产生输出:
<p><img width="300" height="300" src="http://www.example.com/wp-content/uploads/2016/04/image.jpg" alt="Is a good computer?" title="Is a good computer?" ></p>
为什么不包含the_title()
?
帮助赞赏。
你可能想看看the_title()'和'get_the_title()''之间的差异。有这样的多个wordpress功能;以'get_'为前缀的函数返回一个值,没有它的函数将返回值 – Andrew