• Hello,

    My client has over 11 “pages” listed. I would like to have it automatically split into 2-3 columns. I basically want to list 4 links in one column, 4 links in another and 3 links in the last column. I found this area of code in the post-template.php file (see below) is this where a loop will go?

    function wp_list_pages($args = ”) {
    742 $defaults = array(
    743 ‘depth’ => 0, ‘show_date’ => ”,
    744 ‘date_format’ => get_option(‘date_format’),
    745 ‘child_of’ => 0, ‘exclude’ => ”,
    746 ‘title_li’ => __(‘Pages’), ‘echo’ => 1,
    747 ‘authors’ => ”, ‘sort_column’ => ‘menu_order, post_title’,
    748 ‘link_before’ => ”, ‘link_after’ => ”
    749 );
    750
    751 $r = wp_parse_args( $args, $defaults );
    752 extract( $r, EXTR_SKIP );
    753
    754 $output = ”;
    755 $current_page = 0;
    756
    757 // sanitize, mostly to keep spaces out
    758 $r[‘exclude’] = preg_replace(‘/[^0-9,]/’, ”, $r[‘exclude’]);
    759
    760 // Allow plugins to filter an array of excluded pages
    761 $r[‘exclude’] = implode(‘,’, apply_filters(‘wp_list_pages_excludes’, explode(‘,’, $r[‘exclude’])));
    762
    763 // Query pages.
    764 $r[‘hierarchical’] = 0;
    765 $pages = get_pages($r);
    766
    767 if ( !empty($pages) ) {
    768 if ( $r[‘title_li’] )
    769 $output .= ‘<li class=”pagenav”>’ . $r[‘title_li’] . ‘

    ‘;
    770
    771 global $wp_query;
    772 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
    773 $current_page = $wp_query->get_queried_object_id();
    774 $output .= walk_page_tree($pages, $r[‘depth’], $current_page, $r);
    775
    776 if ( $r[‘title_li’] )
    777 $output .= ‘
    ‘;
    778 }
    779
    780 $output = apply_filters(‘wp_list_pages’, $output, $r);
    781
    782 if ( $r[‘echo’] )
    783 echo $output;
    784 else
    785 return $output;
    786 }
    ====================
    this is the php loop I found but I don’t know how to modify it and incorporate it into wordpress. any help would be great. here is the php loop code.

    <?php
    /*** the number of columns wide ***/
    $num_cols = 3;
    /*** and array to traverse ***/
    $animals = array(
    ‘platypus’,
    ‘wallaby’,
    ‘dingo’,
    ‘wombat’,
    ‘kangaroo’,
    ‘steve irwin’,
    ’emu’,
    ‘kookaburra’,
    ‘crocodile’);
    ?>

    <table>
    <tr
    style=”background:orange;”><td>Only</td><td>This</td><td>Wide</td></tr>
    <?php
    /*** set a counter ***/
    $i = 0;
    /*** loop over the array ***/
    foreach ( $animals as $item )
    {
    /*** use modulo to check if the row should end ***/
    echo $i++%$num_cols==0 ? ‘</tr><tr>’ : ”;
    /*** output the array item ***/
    echo ‘<td>’.$item.'</td>’;
    }
    ?>
    </tr>
    </table>

Viewing 1 replies (of 1 total)
  • Have you thought about trying to make this work with CSS? It might be possible.

    Secondly, you are talking about a core edit. Core edits make upgrading painful. Avoid it if you can. Think about using get_pages() and writing your own script to print the list.

Viewing 1 replies (of 1 total)
  • The topic ‘List Pages split into columns’ is closed to new replies.