How To Display Two Columns For Categories In WordPress
Written by Nile | Posted in WordPress | Posted on
02-02-2012 |
15 Comments
Tags: wordpress categories, wordpress tricks
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.






WordPress is very useful for beginners in website design. Thanks for the useful coding information.
Ryan recently posted..Luxury Ski Homes Market Report
Twitter: techsparx1
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
vishvast recently posted..Lenovo’s new IdeaPad Yoga
Thanks for the info you’ve shared
success is always
Abed Saragih Blog
Twitter: VirdiAmrik
says:
Hi Nile.. Thanks for sharing this tutorial. It is really helpful for me. I will use it for my clients websites.Cheers.
Amrik recently posted..4 Best Blogging Platform For Team Blog
Twitter: martyinmaui
says:
I always appreciate the useful information you provide – and especially that it’s not just the same old stuff. Thanks!
marquita herald recently posted..The Kindness Movement: From Tiny Ripple to Worldwide Rally
Twitter: ForteProperties
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!
Chris recently posted..How To Buy a Home With No Banks: Owner Financed Homes Austin
Whilst on the subject of two columns, is there a way of splitting WordPress content into two columns?
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…
matt recently posted..Chatroulette, Omegle Not Safe for Kids
Twitter: Kajal_Agarwal_
says:
I don’t have any idea bout coding..!
But i just follow the copy and paste technique!!!
Kajal Agarwal recently posted..Kajal Agarwal Fitness Secret
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.
Matthew London recently posted..Babalou
Thank you so much for this post.I found lots of interesting information here. And thanks for sharing it’s really wonderful and useful =)))
Twitter: flashyinteract
says:
Thanks for posting this tutorial. I posted something similar to this on my blog. This tutorial is easy to follow.
thanks for this tutorial. very easy to follow, it’s very helpful. will share this to my wordpress buddies
japh recently posted..Coconut candies
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.
Arjun Rai recently posted..Classic Cars
Thank you for sharing this it is very useful to me…..very easy to follows…..
http://www.findghar.com