在WordPress中,我使用此功能显示所有标签
<?php
$tags = get_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;
?>
然后打印出所有标签。
除了显示所有标签之外,还有一种方法可以说明我想要哪些标签来显示slug和链接?
我也试过这个
<?php
$tags = query_posts('tag=html');
$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;
?>
我确定答案在此页面上,但我无法提出解决方案http://codex.wordpress.org/Function_Reference/get_the_tags
答案 0 :(得分:0)
似乎这个解决方案可能不仅仅是手动链接它们,而是你可以做类似的事情......
<?php
$tags = query_posts('tag=html');
$html = '<div class="post_tags">';
$wanted_tags = array ( "aSlugThatIWant", "AnotherSlugThatIWant" );
foreach ( $tags as $tag )
{
if (in_array($tag->slug, $wanted_tags))
{
$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;
?>
编辑:修正了一个错误。