我在WordPress使用这个:为什么将一个PHP函数分配给一个变量执行它?
<?php if (!is_front_page()) {
$title = the_title();
echo <<<EOT
<div class="featured-header col-xs-12 col-sm-12 col-md-12 col-lg-12 cf">
<span class="featured-title">$title</span>
</div>
EOT;
} ?>
然而,由PHP股利前生成的页面标题。它看起来像$ title变量本身的声明执行the_title()
函数。
这是为什么?
编辑:
感谢您的解释!这是现在的工作代码:
<?php if (!is_front_page()) {
$title = get_the_title();
$thumbnail = get_the_post_thumbnail_url();
echo <<<EOT
<div class="featured-header col-xs-12 col-sm-12 col-md-12 col-lg-12 cf" style="background-image: url('$thumbnail');">
<span class="featured-title animated fadeIn">$title</span>
</div>
EOT;
} ?>
你不分配功能,你调用该函数和指派返回值给你变量。 – aynber
那么我应该如何将它分配给这个变量,以便我可以在HEREDOC中调用它? – Andrew
http://php.net/manual/en/functions.variable-functions.php – litelite