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