首先,你把PHP语法搞砸了。其次,您误用了一些WordPress模板标记-您已经重复了整个链接,因此您需要返回post permalink和title,但现在the_permalink
和the_title_attribute
函数响应代码。
以下是已修复的代码:
foreach( $terms as $term ) :
$customposts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=2" );
if( $customposts->have_posts() ):
echo \'<div class="one_half last">\';
echo \'<ul>\';
while( $customposts->have_posts() ) : $customposts->the_post();
echo \'<li>\';
echo \'<a href="\' . get_permalink() . \'">\' . get_the_title(); // The problem
echo \'</a></li>\';
endwhile;
echo \'</ul>\';
echo \'</div>\';
endif;
endforeach;