Site icon Mobilize Cloud

Displaying All Tags For A WordPress Site

WordPress logo
Share:

When working on a WordPress site you might come across a request to build a tag list/cloud/directory for all the tags that are setup in the site that are associated with at least one or more posts.

We looked everywhere for code that would do this and we kept running across the same examples that only showed how to display the tags associated with a single post not all posts.

But then we found it and it was so simple, we created a new WordPress page using a custom template. In that template we placed the following php code.

<ul id="Genre-List">
    <?php
        $tags = get_tags();
        foreach ( $tags as $tag ) :
        $tag_link = get_tag_link( $tag->term_id );
    ?>
    <li>
        <a href='<?php echo $tag_link; ?>' title='<?php echo $tag->name; ?>' class='<?php echo $tag->slug ?>'><?php echo $tag->name ?></a>
    </li>
    <?php
        endforeach;
    ?>
</ul>

The tags are already sorted alphabetically when calling the get_tags(); function.

Get Tags Function

With this function and the use of a simple foreach loop you can retrieve information each tag that is associated with your posts in WordPress.

You can pass a variety of different parameters inside the open and closing () of the function call.

Inside of the foreach loop you can reference any of the following:

$tag->term_id
$tag->name
$tag->slug
$tag->term_group
$tag->term_taxonomy_id
$tag->taxonomy
$tag->description
$tag->parent
$tag->count

Share:
Exit mobile version