How To Display Two Columns For Categories In WordPress

Written by | Posted in WordPress | Posted on Date 02-02-2012 | Comments 15 Comments
Tags: ,

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.

This is also for connecting via social network handles.

Related Posts

About Nile Flores

Nile is 30 year old female from Southern Illinois. Nile is a mother of 1 son. She is also a web and graphic designer, who exclusively designs using WordPress. She is currently a student working for a Bachelors in Business. She also blogs at WPAddict.net and FamousBloggers.net

Connect with Nile at: Twitter | Facebook | LinkedIn

Nile has written 686 articles at Blondish.net.

Comment Policy

Please do not leave just keywords for your name. You will no longer be approved. The correct way to leave your name is YOUR NAME @ YOUR KEYWORD or YOUR NAME | KEYWORD if you choose to use a keyword.

Comments (15)

  • Ryan says:

    WordPress is very useful for beginners in website design. Thanks for the useful coding information.
    Ryan recently posted..Luxury Ski Homes Market ReportMy Profile

  • vishvast
    Twitter:
    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 YogaMy Profile

  • Abed Saragih says:

    Thanks for the info you’ve shared

    success is always
    Abed Saragih Blog

  • Amrik from Monetize Blogging
    Twitter:
    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 BlogMy Profile

  • 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 RallyMy Profile

  • Chris from Owner Financing
    Twitter:
    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 AustinMy Profile

  • 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…
    matt recently posted..Chatroulette, Omegle Not Safe for KidsMy Profile

  • I don’t have any idea bout coding..!
    But i just follow the copy and paste technique!!!
    Kajal Agarwal recently posted..Kajal Agarwal Fitness SecretMy Profile

  • 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..BabalouMy Profile

  • 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
    Twitter:
    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
    japh recently posted..Coconut candiesMy Profile

  • 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.
    Arjun Rai recently posted..Classic CarsMy Profile

  • jobin says:

    Thank you for sharing this it is very useful to me…..very easy to follows…..

    http://www.findghar.com

  • Write a comment

    CommentLuv badge