• Resolved 916VT

    (@vincent916)


    Hello,

    I’m looking for a list of all tags with a special class on the current one.

    I found this code which works great but I can’t manage to add the special class…

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

    Any help ?

    Thanks a lot !

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter 916VT

    (@vincent916)

    I’m trying to figure something like that :

    $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}" . if ( single_tag_title == $tag->name ) { echo 'current'} . "'>";

    But without success so far…

    Any help is more than welcome =)

    try using a ternary operator; example:

    $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}" . ( single_tag_title( '', false ) == $tag->name ? " current" : "" ) . "'>";
    Thread Starter 916VT

    (@vincent916)

    It works perfectly fine !

    Thanks a lot alchymyth, you’re my hero 🙂

    Thanks again !

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Show current tag’ is closed to new replies.