【问题标题】:Why does .the_time() appear before content为什么 .the_time() 出现在内容之前
【发布时间】:2025-12-07 13:30:01
【问题描述】:

在以下短代码中,get_the_title() 显示在 * 和 # 字符之间,如预期的那样。但是 the_time() 始终显示在页面顶部而不是内容内部。为什么 the_time() 会这样做?

有没有办法让发布时间出现在内容中?

function get_recent_posts3() {
    $args = array('cat' => 8, 'posts_per_page' => '2');
    $the_query = new WP_Query( $args );
    $postcontent = '';
    while ( $the_query->have_posts() ) :
        $the_query->the_post();
        $timestamp = '**<br>'.get_the_title().'##'.the_time('F j, Y').'<br>**';
        $postcontent = $postcontent.$timestamp;
    endwhile;
    return $postcontent;
    wp_reset_postdata();
}
add_shortcode('getrecentposts3', 'get_recent_posts3');

输出:

March 12, 2013March 3, 2013 **
Second Post Title##
****
First Post Title##
** 

将 'cat' => 8 替换为有效的类别 ID 以运行代码。

【问题讨论】:

    标签: php wordpress shortcode


    【解决方案1】:

    the_time() 回显时间,使用 get_the_time() 代替。

    【讨论】:

      最近更新 更多