• Resolved BillyBob

    (@williamkharvey)


    Hi all, I’ve put together the following code to split a list of pages in to two columns. It prints ok but as one column. Any idea where the mistake may be?

    Thanks

    <?php
        $children = get_pages('child_of='.$post->ID);
        $parent = $post->post_parent;
        $siblings =  get_pages('child_of='.$parent);
        if( count($children) != 0) {
           $args = array(
             'depth' => 1,
             'title_li' => '',
             'child_of' => $post->ID
           );
        } elseif($parent != 0) {
            $args = array(
                 'depth' => 1,
                 'title_li' => '',
                 'exclude' => $post->ID,
                 'child_of' => $parent
               );
        }
    
        if(count($siblings) > 1 && !is_null($args))  {
    
    $list = wp_list_pages($args);
    $list_elements = explode('</li>', $list);
    $num = count($list_elements)-1;
    
    $col = 2; //set the number of columns
    $num_col = ceil($num/$col);
    $width = floor(290/$col)-5;
    $style = 'width:'.$width.'%;float:left;';
    
    for( $i=1; $i<$col; $i++) { $list_elements[$i*$num_col] = '</ul><ul class="related-practice-areas" style="'.$style.'">'.$list_elements[$i*$num_col]; }
    $list = implode('</li>', $list_elements); ?>
    <?php  echo $list; } ?>
Viewing 1 replies (of 1 total)
  • Thread Starter BillyBob

    (@williamkharvey)

    OK, I sorted this.

    I missed out the echo.

    Here’s the final working code…

    <?php
        $children = get_pages('child_of='.$post->ID);
        $parent = $post->post_parent;
        $siblings =  get_pages('child_of='.$parent);
        if( count($children) != 0) {
           $args = array(
             'depth' => 1,
             'title_li' => '',
             'child_of' => $post->ID,
             'echo' => 0
           );
        } elseif($parent != 0) {
            $args = array(
                 'depth' => 1,
                 'title_li' => '',
                 'exclude' => $post->ID,
                 'child_of' => $parent,
                 'echo' => 0
               );
        }
    
        if(count($siblings) > 1 && !is_null($args))  
    
    $list = wp_list_pages($args);
    $list_elements = explode('</li>', $list);
    $num = count($list_elements)-1;
    
    $col = 2; //set the number of columns
    $num_col = ceil($num/$col);
    $width = floor(100/$col)-0;
    $style = 'width:'.$width.'%;margin-right:0%;padding-left:0%;float:left;';
    
    for( $i=1; $i<$col; $i++) { $list_elements[$i*$num_col] = '</ul><ul class="related-practice-areas" style="'.$style.'">'.$list_elements[$i*$num_col]; }
    $list = implode('</li>', $list_elements); ?>
    
    <ul class="related-practice-areas" style=" <?php echo $style; ?>">
    <?php echo $list; ?>
    </ul>
Viewing 1 replies (of 1 total)
  • The topic ‘split wplist pages in to two columns.’ is closed to new replies.