wp_list_pages

Definition:
function wp_list_pages($args = '') {}

Retrieve or display list of pages in list (li) format.

Parameters

  • array|string $args: Optional. Override default arguments.

Return values

returns:HTML content, if not displaying.

Defined filters

  • wp_list_pages_excludes
    apply_filters('wp_list_pages_excludes', $exclude_array)
  • wp_list_pages
    apply_filters('wp_list_pages', $output, $r)

Source code

function wp_list_pages($args = '') {

	$defaults = array(

		'depth' => 0, 'show_date' => '',

		'date_format' => get_option('date_format'),

		'child_of' => 0, 'exclude' => '',

		'title_li' => __('Pages'), 'echo' => 1,

		'authors' => '', 'sort_column' => 'menu_order, post_title',

		'link_before' => '', 'link_after' => '', 'walker' => '',

	);



	$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't put a nullstring into the array)

	$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();

	$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );



	// Query pages.

	$r['hierarchical'] = 0;

	$pages = get_pages($r);



	if ( !empty($pages) ) {

		if ( $r['title_li'] )

			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';



		global $wp_query;

		if ( is_page() || is_attachment() || $wp_query->is_posts_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, $r);



	if ( $r['echo'] )

		echo $output;

	else

		return $output;

}

3861

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: