[英]Print inside print php
How do i print INSIDE the defined tag? 如何在定义的标签内打印? When it ouputs this code, the_title() gets printed OUTSIDE (before) the h1 tag..
输出此代码时,the_title()将在h1标记之前(之外)打印。
My code is: 我的代码是:
<?php
if ( '' != get_the_post_thumbnail() ) {
print '<p>HEY</p>';
}
else {
print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">', the_title() ,'</h1></div>';
}
?>
i have already tried: 我已经尝试过:
<?php
if ( '' != get_the_post_thumbnail() ) {
print '<p>HEY</p>';
}
else {
print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">'. the_title() .'</h1></div>';
}
?>
What am i doing wrong? 我究竟做错了什么?
Thanks 谢谢
You could do like below: 您可以执行以下操作:
<?php if ( '' != get_the_post_thumbnail() ): ?>
<p>HEY</p>
<?php else: ?>
<div class="page-header row full"><h1 class="page-title" itemprop="headline"><?php the_title(); ?></h1></div>
<?php endif; ?>
Or use get_the_title()
(which returns the title value) instead. 或者使用
get_the_title()
(返回标题值)代替。
Try print "....".get_the_title().".....";
尝试
print "....".get_the_title().".....";
The methods "the_xxxx" print the value, the methods "get_the_xxx" returns the value. 方法“ the_xxxx”打印该值,方法“ get_the_xxx”返回该值。
try echo instead of print 尝试用echo代替print
echo - can output one or more strings
print - can only output one string, and returns always 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.