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 } ?>
  • 1
    Sorry, but this actually is a CSS question, right?
    – kaiser
    Commented Aug 28, 2013 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
    Commented Aug 28, 2013 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
    Commented Aug 28, 2013 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? Commented Aug 28, 2013 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
    Commented Aug 29, 2013 at 11:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.