WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to display sub pages in columns. Some parent pages have a lot of sub pages and the scroll is very long.

I am currently using the below code to display sub pages.

    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children)
 { ?>
   <div id="subNav">
       <?php echo $children; ?>
 } ?>

The child pages will need to appear if you are on another page in the same section (parent page)

Any help much appreciated


Update: 29/08/2013

I have used the following code to generate the pages in columns. The pages now also display once on a child page:

$list = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); //keep 'echo=0' and 'depth=1'; add all your parameters;
$list = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); //keep 'echo=0' and 'depth=1'; add all your parameters;

if( $list ) {
    $list_elements = explode('</li>', $list);
    $num = count($list_elements)-1;

    $col = 3; //set the number of columns
    $num_col = ceil($num/$col);
    $width = floor(100/$col)-5;
    $style = 'float:left;'; ?>

    <div id="subNavWrap">
    <div id="subNav">
    for( $i=1; $i<$col; $i++) {
        $list_elements[$i*$num_col] = '</ul><ul class="subChild">'.$list_elements[$i*$num_col];

        $list = implode('</li>', $list_elements); ?>
          <ul class="subChild"><?php echo $list; ?></ul>

        <?php } ?>
share|improve this question
Sorry, but this actually is a CSS question, right? – kaiser Aug 28 '13 at 9:20
I don't think so. The pages can easily be displayed in one column, but I am looking to display the pages in 3 - 4 columns – rikardo85 Aug 28 '13 at 9:32
It is a CSS/HTML question with some PHP maybe. There is nothing distinctly "WordPress" about it and I'd be surprised if some of the "Related" questions didn't suggest the solution. – s_ha_dum Aug 28 '13 at 14:12
How are you determining the number of columns to use? For example, did you add a setting in the admin; is it based on something else; or hard-coded in the PHP? – Charles Clarkson Aug 28 '13 at 23:51
Charles - please see the edited post above with the code I am using. To determine the columns, I edit the $col variable value. – rikardo85 Aug 29 '13 at 11:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.