Displaying two columns for categories in your WordPress is not too hard. Just takes a little php, html, and css. You can put this in your posts, pages, or sidebar.
We are taking the usual category code for WordPress.
<?php wp_list_categories(); ?>
and replacing it with the following code. This php splits up each category and into columns, much like splitting odds and evens. This code would go in your template where you want it 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].''; elseif ($i>=$cat_n/2): $cat_right = $cat_right.'<li>'.$cats[$i].'</li>'; endif; endfor; ?>
After you have put the above code you are ready to add your HTML right after it. Remember you need to make sure to remember your css class definition, because you will be adding it to your theme’s stylesheet. Remember you can use your own definitions, but remember to make sure you are not already using them for another part of your theme.
<ul class="alignleft"> <?php echo $cat_left;?> </ul> <ul class="alignright"> <?php echo $cat_right;?> </ul>
Now that you have the php and html done, you need to add your css. In the case of this tutorial, I have used alignleft and alignright for the classes.
.alignleft { float: left; } .alignright { float: right; }
Of course, if you want to play with the css and do other things, by all means go ahead.
Ryan says
WordPress is very useful for beginners in website design. Thanks for the useful coding information.
vishvast says
hiii
nile
i was really in search for that hw i will dispaly two colums in categories so i got it here thnx for the complete codes and script very helpful
Abed Saragih says
Thanks for the info you’ve shared
success is always
Abed Saragih Blog
Amrik says
Hi Nile.. Thanks for sharing this tutorial. It is really helpful for me. I will use it for my clients websites.Cheers.
marquita herald says
I always appreciate the useful information you provide – and especially that it’s not just the same old stuff. Thanks!
Chris says
Learn something new every day! It’s always beneficial to learn new ways to customize my wordpress blog. Not only will i use this on my site, i’m going to recommend it to friends!
Matthew London says
Whilst on the subject of two columns, is there a way of splitting WordPress content into two columns?
matt says
Thanks, it’s very easy to understand instruction.
Nile, can you also create a post on how to change background color. I would like to tweak the background of coraline theme I am currently using. Thanks…
Kajal Agarwal says
I don’t have any idea bout coding..!
But i just follow the copy and paste technique!!!
Matthew London says
I answered my own question on how to split content into two columns. There is a plugin available WP Post Columns. It does it nicely for me.
Anonymous says
Thank you so much for this post.I found lots of interesting information here. And thanks for sharing it’s really wonderful and useful =)))
Bobby says
Thanks for posting this tutorial. I posted something similar to this on my blog. This tutorial is easy to follow.
japh says
thanks for this tutorial. very easy to follow, it’s very helpful. will share this to my wordpress buddies
Arjun Rai says
i have multiple wordpress sites and really these types of tips help to every wordpess owner, those are new and even who are some experience holder.
jobin says
Thank you for sharing this it is very useful to me…..very easy to follows…..
http://www.findghar.com
akasharora says
Thank You very much Nile for writing such a great tutorial. Well Would you tell me How I can show Categories in 4 or 5 columns. Actually I want to show them in the footer of my blog.