WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a section in my sidebar where I'd like to display my most popular tags in two columns. I found this post from WPSnipp that details how to narrow your list down to only the most popular, however I'm wondering how I can arrange them to appear in two columns - 10 on the left, and 10 on the right in alphabetical order.

Here's what I'm using: functions.php

function top_tags() {
        $tags = get_tags();
        if (empty($tags))
        $counts = $tag_links = array();
        foreach ( (array) $tags as $tag ) {
                $counts[$tag->name] = $tag->count;
                $tag_links[$tag->name] = get_tag_link( $tag->term_id );
        $counts = array_reverse( $counts, true );
        $i = 0;
        foreach ( $counts as $tag => $count ) {
                $tag_link = clean_url($tag_links[$tag]);
                $tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
                if($i < 11){
                        print "<li><a href=\"$tag_link\">$tag ($count)</a></li>";


<h2 class="widgettitle">#HASHTAG</h2>
        <? $tags = top_tags();
        $tags_count = count($tags);
        $number = ceil($tags_count / 2);
        $args = array('number' => $number);
        $tagsleft = get_tags($args);
        $args = array('number' => $number, 'offset' => $number);
        $tagsright = get_tags($args);

        $html = '<ul class="catleft">';
            foreach ($tagsleft as $tag){
                $tag_link = get_tag_link($tag->term_id);

                $html .= "<li><a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
                $html .= "{$tag->name}</a></li>";
            $html .= '</ul>';

            $html .= '<ul class="catright">';
            foreach ($tagsright as $tag){
                $tag_link = get_tag_link($tag->term_id);

                $html .= "<li><a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
                $html .= "{$tag->name}</a></li>";
            $html .= '</ul>';
            echo $html;
share|improve this question
up vote 1 down vote accepted

In my opinion you are doing it so complicated.

I would rather do a classic query and then through css it made into 2-column.

function top_tags() {
    $tags = get_the_tags();

             $output = '<h4>Top tags</h4> <ul class="top_tags">';
             foreach($tags as $tag)
                   $output .= '<li><a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'">'.$tag->name.'</a></li>';

             $output .= '</ul>';

             echo $output;

and your css

.top_tags li {display:block; float:left; width:50%; clear:right;}
share|improve this answer
Works perfectly (ignore my previous content, found the problem). Thanks again for your help. – user1255049 Oct 27 '13 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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