查询需要的是标记slug,而不是标记名称:
$tag = $tag->slug . \' \';
查询语法错误;已更正:
query_posts(\'tag=\'.$tag.\'&posts_per_page=-1\');
编辑:重新排列的完整代码:
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$tag = $tag->slug; break;
}
query_posts(\'tag=\'.$tag.\'&posts_per_page=-1\');
while (have_posts()) : the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile;
wp_reset_query();
}