WordPress blogroll in 2 columns

It’s been quite a mission working out how I would take the blogroll and split the links across two columns. There wasn’t anything on Google so I set forth to put something together, here’s the code:

<div class=”blogroll-foot”><H4>Blog Roll</H4>
<ul>
<?php
$links = wp_list_bookmarks(‘title_li=&categorize=0&sort_column=menu_order&echo=0′);
$bookmarks = explode(‘</li>’, $links);
$links = $bookmarks;
$link_n = count($links) – 1;
for ($i=0;$i<$link_n;$i++):
if ($i<$link_n/2):
$left = $left.’<li>’.$links[$i].’</li>’;
elseif ($i>=$link_n/2):
$right = $right.’<li>’.$links[$i].’</li>’;
endif;
endfor;
?>
<ul class=”left_blogroll”>
<?php echo $left;?>
</ul>
<ul class=”right_blogroll”>
<?php echo $right;?>
</ul>
</ul>
</div>

Then all you have to do is create two css classes left_blogroll with a float left and right_blogroll with a float right and you should be set.

Hope you find it useful!

Wordpress guru is our Wordpress expert, from Wordpress themes to plugins to tips and tricks, he provides us with everything we should know about Wordpress!

Enjoy this post? Please tell a friend:

17 Comments on "WordPress blogroll in 2 columns"

  1. MarkB says:

    I would have done it a bit simpler…

    If you display:block the LI’s, and then float them left and give them a width (50% of the width of your parent column), then you’ll achieve the same effect, without the bothersome PHP code :)

    Just a thought :)

  2. Chris M says:

    Lol, so after my 50 tweets about it, you decide to offer a solution after I’ve pulled my hair out to solve it?

  3. Mark says:

    soz man.. missed those tweets :P

  4. Chris M says:

    hehe, it’s all good my friend :)

  5. Brendon says:

    Haha nice one Mark. So the blogroll structure would be:

    item1 item2
    item3 item4

    Chris was just telling me how css is php’s bitch :)

  6. Chris M says:

    CSS has NOTHING on PHP, absolutely nothing.

  7. Mark says:

    Yeah @Brendon, you’d end up with that structure.

    There is a jQuery plugin you could use if you NEEDED

    item1 item3
    item2 item4

  8. Chris M says:

    Sounds like a CSS hack to be honest :P

  9. john says:

    Thanks for the example code, could you also show what to write for the css floats

  10. Chris M says:

    My pleasure John, unfortunately floats are a bit off topic here, but I’m sure by Googling you’ll find some good resources..

  11. Helen D says:

    This doesn’t work for me. I am using the same method for categories which works fine – but when I put the blogroll code in (as above) the whole sidebar stops displaying.

    If you have any tips for what to double check – or why I might be having these problems, that would be really great.

    Thanks

  12. Chris M says:

    What version of WordPress are you running?

  13. Helen D says:

    Hello Chris – even if you can’t help, I’m so pleased to know someone’s out there!

    Anyway, I’m running 2.9.2

    Worst case scenario, I will aim to get the site on a live server over the next few days and write a more detailed post of the couple of things I want to achieve with the blogroll and category columns, but am so far not quite managing. I can then add screenshots and code as well as the site itself being a reference.

    If I can get the blogroll working in two columns like the categories do, that will take care of one of the issues I have when I attempt to use the shorter li 50% / float left method for the blogroll. It’s only a visual alignment issue, as this method does technically work to produce faux columns, but in order for the visual thing to be fixed, really I need the categories and blogroll to split into 2 columns using the same method – and the explode method is my preference.

    Out of interest, do you know if there’s a way to use the explode method on the categories (the bit of code that is working for me) to display child categories hierarchically? I have my depth set to 2, so I can see the child categories displayed, but they all show as if they are top level parent categories. It would be great to be able to handle and style the child cats differently.

    That last bit is just an extra question – definitely getting the blogroll explode code to work would be great.

    Many thanks for replying, H

  14. Michael says:

    There is an out of date plugin that will create multi-colums for the blogroll but it does not seem to work nicely with WP3.x

    Too bad there isn’t a plugin that does work since having a multiple column layout for a links page would be highly desirable.

  15. Chris M says:

    I wish I had more time, I’d put one together :(

    The requirement for multi-column blogrolls, categories and so forth has always been a want by WordPress users, I find it amazing that someone hasn’t built a widget!

  16. Jenn says:

    I just tried this code verbatim, and I’m getting a syntax error. I’m not sure if I’m missing something obvious (though again, I copied the code *verbatim*, so I don’t see how that’s possible), or if this is now outdated?

  17. Chris M says:

    Hi Jenn, yeh, this code was unfortunately written in 2010 and there have been countless updates to WordPress since then so I’m not surprised that it didn’t work. I’ll see if I can put some code together for you.

Got something to say? Go for it!