How to display wordpress top level pages

Displaying wordpress top level pages may be useful for displaying sitemap or browse interface on a wordpress site. Here is the code you can use for this:

// List of pages you want to exclude.
// Put null if nothing needs to be excluded.
$exclude = "1000,1001";
$args = array(
        'depth'        => 1,
        'show_date'    => '',
        'date_format'  => get_option('date_format'),
        'child_of'     => 0,
        'exclude'      => $exclude,
        'include'      => '',
        'title_li'     => __(''),
        'echo'         => 1,
        'authors'      => '',
        'sort_column'  => 'menu_order, post_title',
        'link_before'  => '',
        'link_after'   => '',
        'walker'       => '',
        'post_type'    => 'page',
        'post_status'  => 'publish'
);
wp_list_pages($args);

Note that we are using depth=1 and child_of value 0 to find top level pages.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments