|
The
wp_list_pages()
function calls
get_pages()
, which can be easily overridden with a different post type. Here's a basic modification of that function which calls
get_posts()
instead. This takes basically the same arguments as
wp_list_pages
, with one additional: *post_type* (set as the name of your post type).
function wp_list_post_types( $args ) { $defaults = array( 'numberposts' =>
-1, 'offset' =>
0, 'orderby' =>
'menu_order, post_title', 'order' =>
'ASC', 'post_type' =>
'page', 'depth' =>
0, 'show_date' =>
'', 'date_format' =>
get_option('date_format'), 'child_of' =>
0, 'exclude' =>
'', 'include' =>
'', itle_li' =>
__('Pages'), 'echo' =>
1, 'link_before' =>
'', 'link_after' =>
'', 'exclude_tree' =>
'' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $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 (but don put a nullstring into the array) $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); $r['exclude'] = implode( ',', apply_filters('wp_list_post_types_excludes', $exclude_array) ); // Query pages. $r['hierarchical'] = 0; $pages = get_posts($r); if ( !empty($pages) ) { if ( $r[itle_li'] ) $output .= '
' . $r[itle_li'] . '
'; global $wp_query; if ( ($r['post_type'] == get_query_var('post_type')) || is_attachment() ) $current_page = $wp_query->
get_queried_object_id(); $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); if ( $r[itle_li'] ) $output .= '
'; } $output = apply_filters('wp_list_pages', $output, $r); if ( $r['echo'] ) echo $output; else return $output;
}
Note: its mostly copy-pasted from source. There's certainly a few arguments left in there that aren doing anything and there might well be some use cases I haven thought of that would break it. It works, surprisingly, though, with both hierarchical andn-hierarchical post types, though...
|