打开我们主题文件夹内的single.php文件,在里面找到代码:the_tags('', ', ', '');直接替换成以下代码:
$posttags = get_the_tags();
$count=0;
if($posttags) {
foreach($posttags as $tag) {
$count++;
if($count<3){
echo '<a href="' . get_tag_link( $tag ) . '" rel="tag" target="_blank">' . $tag->name . '</a> ';
}
}
}
其中代码中的3就是表明输出2个标签,如果想输出3个就只需把代码中的3改为4即可。
我想把tag标签只要6个显示,于是把以下代码:
<?php $posttags = get_the_tags();
$count=0;
if($posttags) {
foreach($posttags as $tag) {
$count++;
if($count<3){
echo '<a href="' . get_tag_link( $tag ) . '" rel="tag" target="_blank">' . $tag->name . '</a> ';
}
}
} ?>