the_title 默认执行了 echo,而 get_the_title 只是获取 title,并不执行 echo。所以 the_title (包括其他the_xxx) 通常用在页面 loop 中,而 get_the_title ( get_the_xxx )用在 PHP 逻辑中。
<p><?php echo get_the_title(); ?></p>
<p><?php the_title(); ?></p>
举例:
if ($posts->have_posts()) :
while ($posts->have_posts()) : $posts->the_post(); ?>
<a href="#" class="product col-lg-4">
<?php the_post_thumbnail($size=array(100, 100), $attr=array('alt' => get_the_title(), )); ?>
<b><?php the_title(); ?></b>
<i><?php the_excerpt(); ?></i>
</a>
<?php
endwhile;
endif;
参考阅读
wordpress 中 the_title 与 get_the_title 的区别https://www.sunzhongwei.com/difference-between-the-title-and-get-the-title-in-wordpress?from=sidebar_related
WordPress教程:如何使用the_title()与the_title_attribute()函数https://yusi123.com/3053.html