wordpress 中 the_title 与 get_the_title 的区别

文章目录

    the_title 默认执行了 echo; 而 get_the_title 只是获取 title,并不执行 echo。

    所以 the_xxx 通常用在页面 loop 中,而 get_the_xxx 用在 PHP 逻辑中。

    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;
    

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式