List Tags of Posts Alphabetically (1 post)

  1. cpatience
    Posted 4 years ago #

    I need some assistance listing tags of posts alphabetically. Right now I use a category page to list a unique instance of the tag associated with the posts within the category.

    For example, a coupon post is created with the category clothing and with the tag 'Sears.' For the Clothing category page, I list the tags for all of the posts, such as 'Sears', 'Kmart', etc.

    Currently I'm using the following code which works, but I'd like to sort these tags alphabetically.

            $project_query = query_posts($query_string . '&orderby=name&order=asc&posts_per_page=-1');
            while (have_posts()) : the_post();
                $posttags = get_the_tags();
                if ($posttags) {
                    foreach($posttags as $tag) {
                        $all_tags_arr[] = $tag -> name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
        <?php if ( is_array($all_tags_arr) && count($all_tags_arr) > 0 ): ?>
        $tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
        foreach( $tags_arr as $tag ):
            $el = get_term_by('name', $tag, 'post_tag');
    		$arr[] = '"tag-'.$el->slug.'"';
        <li><a href="<?php echo get_bloginfo('url'); ?>/?tag=<?php echo $el->slug; ?>" id="taglink-tag-<?php echo $el->slug; ?>" rel="tag-<?php echo $el->slug; ?>"><?php echo $el->name; ?></a> </li>
    <?php endforeach; ?>
    </ul><?php endif; ?>

    I'm guessing that somehow I need to sort $el alphabetically, but I'm not sure how. Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic