功能get_the_tags();
可能就是你要找的。以下代码显示标记列表,其中包含指向每个标记的链接以及每个标记的特定类:
<?php
$tags = get_the_tags();
$html = \'<div class="post_tags">\';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<a href=\'{$tag_link}\' title=\'{$tag->name} Tag\' class=\'{$tag->slug}\'>";
$html .= "{$tag->name}</a>";
}
$html .= \'</div>\';
echo $html;
?>
现在,使用该逻辑,我修改了您的代码以满足您的需要:
<?php if( has_tag() ) { ?>
<div id="tagWrapper">
<p>Tags</p>
<?php
$tags = get_the_tags();
$html = \'<ul class="tags">\';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<li class="tag-body olive"><a href=\'{$tag_link}\' title=\'{$tag->name} Tag\' class=\'{$tag->slug}\'>";
$html .= "{$tag->name}</a></li>";
}
$html .= \'</ul>\';
echo $html;
?>
</div>
<?php } ?>
如果有帮助(尽管未经测试),输出应如下所示:
<div id="tagWrapper">
<p>Tags</p>
<ul class="tags">
<li class="tag-body olive">
<a href=\'http://example.com/tag/technology/\' title=\'Technology Tag\' class=\'technology\'>Technology</a>
</li>
<li class="tag-body olive">
<a href=\'http://example.com/tag/gadgets/\' title=\'Gadgets Tag\' class=\'gadgets\'>Gadgets</a>
</li>
<li class="tag-body olive">
<a href=\'http://example.com/tag/mobile/\' title=\'Mobile Tag\' class=\'mobile\'>Mobile</a>
</li>
</ul>
</div>
SOURCE: WordPress Codex Function Reference for get_the_tags();