Jon Breitenbucher
Member
Posted 1 year ago #
Hello,
I'm trying to split the result of wp_list_bookmarks() in half so that I can display the links in two columns. I have tried the following
<?php // display bookmarks in two columns
$cats = explode("</span>",wp_list_bookmarks('category_before=<span><li id=%id class=%class>&category_after=</li></span>'));
$cat_n = count($cats) - 1;
for ($i = 0; $i < $cat_n; $i++):
echo $cats[$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 class="left">
<?php echo $cat_left; ?>
</ul>
<ul class="right">
<?php echo $cat_right; ?>
</ul>
but it seems like the explode is not returning anything. Have I made an obvious mistake somewhere?
you would at least have to set the 'echo' parameter to false in 'wp_list_bookmarks()' to use it as an string in the 'explode' function.
http://codex.wordpress.org/Function_Reference/wp_list_bookmarks
i didn't check anything else, yet.
however, from the 'explode' you are probably missing a </span> somewhere in your reconstructured lists.
Jon Breitenbucher
Member
Posted 1 year ago #
Thanks alchymyth. That was all I needed. Here is the working code
<?php
$cats = explode('</span>',wp_list_bookmarks('category_before=<span><li id=%id class=%class>&category_after=</li></span>&echo=0'));
$cat_n = count($cats) - 1;
for ($i = 0; $i < $cat_n; $i++):
if ($i < $cat_n/2):
$cat_left = $cat_left.$cats[$i].'</span>';
elseif ($i >= $cat_n/2):
$cat_right = $cat_right.$cats[$i].'</span>';
endif;
endfor; ?>
<ul class="left">
<?php echo $cat_left; ?>
</ul>
<ul class="right">
<?php echo $cat_right; ?>
</ul>