Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm nearly there with this, but I need to highlight the current tag link/archive being viewed:

<ul id="blog-tags">
            <?php 
            $tags = get_tags();
            if ($tags) {
                foreach ($tags as $tag) {
                    echo '<li><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></li>';
                }
            }
             ?>
        </ul>

I'd like to apply <li class="active-tag"> to the list item that contains the active tag in the code above - can anyone help me with that please?

Many thanks

Osu

share|improve this question
    
Look at this thread : questions/16816 –  JMau Aug 11 '13 at 13:05

1 Answer 1

up vote 2 down vote accepted

Compare $tag->term_id with the value from get_queried_object_id(). You have to cast the former to integer, because it is provided as a string for no good reason.

<ul id="blog-tags">
<?php
$tags = get_tags();
if ( $tags ) {
    foreach ( $tags as $tag ) {
        echo '<li>';

        if ( (int) $tag->term_id === get_queried_object_id() )
            echo "<b>$tag->name</b>";
        else
            printf(
                '<a href="%1$s">%2$s</a>',
                get_tag_link( $tag->term_id ),
                $tag->name
            );

        echo '</li>';
    }
}
?>
</ul>
share|improve this answer
    
Great, fantastic answer, thanks toscho! –  Osu Aug 11 '13 at 13:08
    
Nice, fav it now –  JMau Aug 11 '13 at 13:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.