0

在 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;
?>

然后打印出所有标签。

除了显示所有标签之外,有没有一种方法可以说我希望它显示哪些标签并链接到?

我也试过这个

<?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

4

1 回答 1

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;
?>

编辑:刚刚修正了一个错误。

于 2013-07-26T01:29:35.417 回答