WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_tags + show description (4 posts)

  1. Nate
    Member
    Posted 3 years ago #

    I have been trying to figure out how to show the tag's description in the loop on my index.php page. I've made extensive use of Google with no solution yet.

    My Code
    <hgroup><?php the_tags('<h3>Authors:</h3><h2>','</h2><h2>','</h2>'); ?></hgroup>

    Basic stuff. That works but when I try to add things below my tags don't show up at all.
    <?php if (is_tag()) { ?><?php echo tag_description(); ?><?php } ?>

    <?php if (is_tag()) { ?><h2><?php echo tag_description(); ?></h2><?php } ?>

    To sum up what I'm looking for. Show all tags' description listed in a post below the tag. A format may look like this.

    <h2>Tag 1</h2>
    <p>Tag 1 Description</p>

    Anyone know about a plugin or any code that can help me?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. Nate
    Member
    Posted 3 years ago #

    I've read that entire page before and after you posted. Maybe I'm missing something but I don't see anything there that help's me modify the_tags code to show a Tag's description.

    I did read about adding:
    <?php } else if ($this_tag->name == "someothertag" ) { ?>

    This would require me to go back and add this statement for every tag I create which will be a daunting task once my tag database becomes really large.

    Is there a simpler solution? One which would just show all descriptions for every tag in the loop?

  4. Nate
    Member
    Posted 3 years ago #

    Kaiser from Stackexchange was able to solve this issue for me.
    http://wordpress.stackexchange.com/users/385/kaiser

    $tags = get_the_tags(); // for the specific post
    // $tags = get_tags(); // all tags
    $html = '<div class="post_tags">';
    foreach ( $tags as $tag )
    {
        $tag_link = get_tag_link( $tag->term_id );
    
        $html .= "Describtion for ".ucfirst( strtolower( $tag->name ) ).": $tag->description";
        $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>{$tag->name}</a>";
        }
    
    $html .= '</div>';
    echo $html;

Topic Closed

This topic has been closed to new replies.

About this Topic