
The stadard wp_list_categories() functions echoes a list of all your categories. Let’s see how we can easily force the display of categories on two columns.

The stadard wp_list_categories() functions echoes a list of all your categories. Let’s see how we can easily force the display of categories on two columns.
Simply paste the following piece of code where you'd like your categories to be displayed:
<?php
$cats = explode("<br />",wp_list_categories('title_li=&echo=0&depth=1&style=none'));
$cat_n = count($cats) - 1;
for ($i=0;$i<$cat_n;$i++):
if ($i<$cat_n/2):
$cat_left = $cat_left.'<li>'.$cats[$i].'</li>';
elseif ($i>=$cat_n/2):
$cat_right = $cat_right.'<li>'.$cats[$i].'</li>';
endif;
endfor;
?>
<ul class="left">
<?php echo $cat_left;?>
</ul>
<ul class="right">
<?php echo $cat_right;?>
</ul>
Then, just save the file, and enjoy!
Credits goes to Blog Oh Blog for this awesome recipe!
49 Responses
Wow, very useful recipe! I will consider this when redesigning my blog
good recipe, i will use it soon in my blog
This is a great and very useful information for me. A little later I will try to set this on my display. Thank you for your instructions.
Hi. Thanks for recipes
I’m using widget ready theme. How can i use this codes. I’m added these codes my functions.php and sidebar.php but it didnt work.
Excellent hack. It’s perfect for blogs with wide sidebar and plenty of categories.
Nice little trick, I’ve used CSS tricks to usually move the
lileft or right. I like this one.What about CSS only:
li.mycat{float:left; display:inline; widht:50%}
Maybe I’m wrong…
Thanks for recipe
It’s a good idea.
You can use this plugin too : http://tinyurl.com/ogokme
Interesting recipe. Thanks to you and BlogOhBlog
It’s fantastic recipe and thanx for sharing this with us.
Nice Snippet. Thanks for sharing – appreciate.
Thanx for the Trick.
Is there a way to sort those columns? If say I wanted some categories on the left and the rest on the right?
Really nice recipe! Gonna cook it at home
!
Thank you, I’m using this on a current project. Comes in handy.
nice tips… i wil try in my weblog.thanks
Great idea for wide content boxes. Thanks, I might try this on one of my new themes for ThemeForest.
Many many thanks for this great technique. It will definitely help me a lot..
Fantastic Recipe. Thanks.
Nice nice.. Saves some good space..
Well this is one tasty recipe and a good snippet. The trick is a nice way of displaying the neat categories on the two sides. Good job with this one.
Till then,
Jean
Nice tip! Now for a two column tag cloud…. anyone know how to do that?
nice trick! thanks..
Great recipe. Thanks for sharing.
Thank you for the great recipe on posting wordpress categories in two columns. This has worked great on my website, and really has cleaned up the interface. It looks a lot nicer showing two columns of categories instead of one really…long…list of categories.
Keep up the great work on the website, I find it really informative.
Thanks for the tips jean. I’ve tried in my blog.
This is useful for blog that have many of categories, but only have short sidebar space
Jean, do you have any sniplet to display blogroll in two columns?
Thanks for the trick.
I will try it ASAP, coz my blog’s category is very long like a tail monkey
great recipe, thanks
Nice! Thanks for the great tip.
Thanks, anyway …. Is there a way to sort those columns? If say I wanted some categories on the left and the rest on the right?
The Recipe worked for me, keep up the good work!
It isn’t working. I get my categories arranged in two lists one underneath the other, divided by a blank line. Like this.
Cat 1
Cat 2
Cat 3
Cat 4
Cat5
Cat6
Cat 7
Cat 8
Anybody know what my problem is?
@Adam : You have to style the lists with CSS
Hi Jean,
I remember when you first published this recipe, very cool! Question – is it possible to do this with wp_list_bookmarks instead of categories?
@Chris M : Haven’t tried it, but in theory it should work
I tried it out and played around for a while, but it wasn’t happening unfortunately :/
Perhaps I missed something small..
Trackbacks: