以下代碼: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