Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Display Category List in Two Columns

Tired of that boring, single-column category display? Spice things up with a spiffy two-column category list that will get your visitors’ hearts pumping. Let’s deface a WordPress tag, shall we?

See this bad boy:

<?php wp_list_categories(); ?>

We’re going to blow it up, divide its contents into two pieces, and spit it all back out as two unordered lists. Impossible, you say? Nah, just a little PHP to make it all go.

Wherever you would like to display your categories in two columns, throw down the following code snippet:

<?php // display categories in columns
$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>';

endfor; ?>

<ul class="left">
	<?php echo $cat_left;?>
<ul class="right">
	<?php echo $cat_right;?>

Completely awesome. Now let’s add some style to make the columns work:

.right {
	float: left; 
	width: 140px;
.left {
	float: left; 
	width: 140px;

You are all set. You should probably fine-tune this business until it’s all good. You know.

Source: Blog Oh Blog (404 link removed 2013/06/24)