WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Tag List

[Resolved] Tag List

  • I am using the following code in my sidebar to show the list of tags with count for each.

    <?php
    $tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
    foreach ( (array) $tags as $tag ) {
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . ' (' . $tag->count . ') </a></li>';
    }
    ?>

    Is there a way to have only the top (for example) 15 tags to show in this list with a link below the tags to a page where I will show all my tags in a specific format, e.g. cloud.

    Cheers,
    Simon.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Like

    <?php
    $count=0;
    $tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
    foreach ( (array) $tags as $tag ) {
    $count++;
    if ($count <=15) {
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . ' (' . $tag->count . ') </a></li>';
    }
    }
    ?>
    <li><a href='http://yourdomain.com/page_with_tag_cloud' title="Cloud with more tags.">Tag Cloud...</a></li>

    Works perfectly… exactly what I was looking for.

    Many thanks!

    Is there a way to list in order of most recently used tag? 🙂

    I am using a similar method to do this with custom taxonomies but I keep seeing a ‘1’ appear at the end of the list. Any ideas?

    <?php
    		$tags = get_terms( array( 'taxonomy' => 'state') );
    		foreach ($tags as $tag) {
    		$tags = print('<a href="' . get_term_link($tag,'state') . '" target="resultsframe">' . $tag->name . '</a>');
    		}
    		echo $tags;
    		?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Tag List’ is closed to new replies.