First off I want to thank you t31os_ for providing this code. It has been of huge assistance to me in achieving the desired formatting on my current project. I've appropriated your code to work with the wp_list_pages tag. It works wonderfully, the only snag I've encountered is that the columns won't balance out when there are an equal number of items in the lists.
For example, I have two columns displaying a total of 10 list items. For some odd reason, instead of balancing out with 5 and 5, it displays as 6 and 4. I've played with the code to try and fix the problem to no avail. When looking in the output source code I noticed that there is an extra /li before the final /ul closing tag. I suspect this may be causing the problem, but can't figure out how to remove that unnecessary closing /li tag.
Here is my code:
<?php
// Grab the pages
$get_pages = wp_list_pages( 'echo=0&title_li=&child_of=28&sort_column=post_title' );
// Split into array items
$pages_array = explode('</li>',$get_pages);
// Amount of page items (count of items in array)
$results_total = count($pages_array);
// How many pages to show per list (round up total divided by 3)
$pages_per_list = ceil($results_total / 2);
// Counter number for tagging onto each list
$list_number = 1;
// Set the pages result counter to zero
$result_number = 0;
?>
<ul id="cat-col-<?php echo $list_number; ?>">
<?php
foreach($pages_array as $pages) {
$result_number++;
if($result_number % $pages_per_list == 0) {
$list_number++;
echo $pages.'</li>
</ul>
<ul id="cat-col-'.$list_number.'">';
}
else {
echo $pages.'</li>';
}
}
?>
</ul>
Here is what the output looks like for the second column (the column displaying 4 items) when I view source:
<ul id="cat-col-2">
<li class="page_item page-item-14"><a href="http://localhost:8888/harris/advertising/music/test-advertising-1/" title="G – Test">G – Test</a></li>
<li class="page_item page-item-55"><a href="http://localhost:8888/harris/advertising/music/h-test/" title="H – Test">H – Test</a></li>
<li class="page_item page-item-57"><a href="http://localhost:8888/harris/advertising/music/i-test/" title="I – Test">I – Test</a></li>
<li class="page_item page-item-59"><a href="http://localhost:8888/harris/advertising/music/j-test/" title="J – Test">J – Test</a></li>
</li>
</ul>
Any help is greatly appreciated.