我在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>