Troy Chaplin  /  Design & Development

Inspiration for the Creative Mind

Blogging about design, development, games and other related topics

Flow WordPress Categories and Blog Roll Across Two Columns

If your design calls for flowing a WordPress categories or blog roll list over two columns then the following functions will allow you to do just that, and style them along the way by using the ul left and right classes.

Categories

Paste the following into your template files where you wish to flow the categories over two columns:


<?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 style="float:left">
<?php echo $cat_left;?>
</ul>
<ul style="float:right">
<?php echo $cat_right;?>
</ul>
<div style="clear:both"></div>

Blog Roll

Paste the following into your template file where you wish to flow the blog roll over two columns:


<?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.''.$links[$i].'';
elseif ($i>=$link_n/2):
$right = $right.''.$links[$i].'';
endif;
endfor;
?>

<ul style="float:left">
<?php echo $left;?>
</ul>
<ul style="float:right">
<?php echo $right;?>
</ul>
<div style="clear:both"></div>

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>