0

I'm displaying a lit of tags when they have a description. I'd like to sort them by name instead of by post quantity. Is there a way to do this?

<?php 
    $tags = get_tags();
    if ($tags) {
      foreach ($tags as $tag) {
        if ($tag->description) {
          echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '><h3>' . $tag->name.'</h3></a></dt><dd style="margin-bottom: 10px;">' . $tag->description . '</dd>';
        }
      }
    }
?>
1

You should use the function wp_tag_cloud, it has many parameters as described in the codex and the one to sort the results as you want: 'orderby' => 'name', 'order' => 'ASC',.

  • How would I pull all teags including those that aren't attached to a post? – Zach Shallbetter Aug 31 '11 at 18:27
  • Set the 'number' parameter to 0, it'll pull all the tags. This function retrieves general tags, not the ones attached to a post. – kevin Aug 31 '11 at 18:44
  • That didn't seem to work. I'm looking to pull absolutely all of the tags. – Zach Shallbetter Aug 31 '11 at 18:56
  • Yes it does. This is the code $args = array('smallest' => 8, 'largest' => 8,'unit' => 'px', 'number' => 0); wp_tag_cloud( $args ); that i used to pull all the tags on this page: regrouped.net/tags-list – kevin Aug 31 '11 at 19:02
  • Wild I wonder what's broken then? The only results I'm getting are from tags that are associated with posts. Not any of the ones that are just listed in the Post Tags and have "0". Every result you have listed on that page is connected to a post. Nice site btw. – Zach Shallbetter Aug 31 '11 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.