Forums

[resolved] Tag List (3 posts)

  1. s872
    Member
    Posted 2 weeks ago #

    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.

  2. MichaelH
    moderator
    Posted 2 weeks ago #

    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>
  3. s872
    Member
    Posted 2 weeks ago #

    Works perfectly... exactly what I was looking for.

    Many thanks!

Reply

You must log in to post.

About this Topic

Tags