WordPress version 2.1
I modified the wp_list_pages function so that it has a limit param. Below is the new function and function call:
function my_wp_list_pages($args = '',$limit=10) {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'),
'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '');
$r = array_merge($defaults, $r);
$output = '';
$current_page = 0;
// sanitize, mostly to keep spaces out
$r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
// Allow plugins to filter an array of excluded pages
$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
// Query pages.
$pages = get_pages($r);
$p2 = array_chunk($pages, $limit);
$pages = $p2[0];
if ( !empty($pages) ) {
if ( $r['title_li'] )
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
global $wp_query;
if ( is_page() )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
if ( $r['title_li'] )
$output .= '</ul></li>';
}
$output = apply_filters('wp_list_pages', $output);
if ( $r['echo'] )
echo $output;
else
return $output;
}
my_wp_list_pages("title_li=&child_of=23&sort_column=post_modified&sort_order=DESC",3);
notice the “,3” in the new function call. This will limit the list to 3 posts. You can set the limit to whatever you wish.