Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

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

Any help much appreciated

Thanks

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:

if($post->post_parent)
$list = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); //keep 'echo=0' and 'depth=1'; add all your parameters;
else
$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">
    <?php 
    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>
    </div>
    </div>

        <?php } ?>
share|improve this question
1  
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

 
discard

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

Browse other questions tagged or ask your own question.