WordPress功能没有正确格式化代码

时间:2014-03-17 12:23:50

标签: php wordpress

我在WordPress中有一个自定义帖子类型,我在一个函数中使用循环,以便我可以使用短代码调用列表。

我正在使用.=添加一个字符串,因为我已经阅读过这是最好的方法。

问题是它没有以正确的格式格式化代码,请参阅下面的代码。

$args = array( 'post_type' => 'gms_product', 'posts_per_page' => 30 );
$loop = new WP_Query( $args );

function get_the_products() {
    global $loop;
    $code = '';
    while ( $loop->have_posts() ) : $loop->the_post();
        $code .=    '<a href="#"><h3>'.the_title().'</h3></a>';
    endwhile;
    return $code;
}

输出看起来像这样。

post1post2 <a href="#"><h3></h3></a><a href="#"><h3></h3></a>

1 个答案:

答案 0 :(得分:3)

尝试使用get_the_title()

$code .=    '<a href="#"><h3>'.get_the_title().'</h3></a>';
相关问题