Site logo

Archived topic

Creating a list of TAGS with post count

3 replies · Started by ch1800 on December 12, 2022

Viewing posts 1–4 of 4

Hello,

I'm not sure this would be supported here but here we go:

Is it possible to create a simple and basic HTML-linked list of all TAGS used at a website with their corresponding count of posts?
Nothing fancy, no cloud rendering, just a basic list that displays all tags with the post count and that is hyperlinked to each tag archive page.

Thanks.

Hi there,

you can create a Shortcode using this PHP Snippet:


add_shortcode ('show_tags', function($html){
    $html = '<ul class="tags-list">';
    $terms = get_terms('post_tag',array('hide_empty'=>false));
    foreach( $terms as $t) {
        $html .= sprintf(
            '<li><a href="%1$s" title="%2$s">%2$s (%3$s)</a></lia>',
            $term_link = get_term_link( $t ),
            $t->name,
            $t->count
        );
    }
    $html .= '</ul>';
    return $html;
});

Then add the [show_tags] shortcode to your page.

Wonderful! Many thanks for this.

Awesome - glad to be of help!

This archived topic is closed to new replies.