• Vince

    (@vincentrich)


    http://codex.wordpress.org/Template_Tags/wp_list_pages

    Exclude Pages from List

    Use the exclude parameter hide certain Pages from the list to be generated by wp_list_pages. Excluding a Page will also exclude all of its sub-pages from the list to be generated.

    I see my sub pages getting displayed. This was not an issue in WP 2.3.3.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Vince

    (@vincentrich)

    wp_list_pages in 2.3.3:

    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'
    	);
    
    	$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
    	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
    
    	// Query pages.
    	$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() )
    			$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;
    }

    wp_list_pages in 2.5:

    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'
    	);
    
    	$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
    	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
    
    	// 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() || $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);
    
    	if ( $r['echo'] )
    		echo $output;
    	else
    		return $output;
    }

    If I copy and paste the 2.3.3 code over the 2.5 code, the wp_list_pages function works properly.

    The only difference between the 2 sets of codes are only:

    //2.3.3
    $pages = get_pages($r);
    
    .......
    
    global $wp_query;
    		if ( is_page() )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
    
    //2.5
    $r['hierarchical'] = 0;
    $pages = get_pages($r);
    
    ..........
    
    global $wp_query;
    		if ( is_page() || $wp_query->is_posts_page )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
    guruxl

    (@guruxl)

    The code will have to be updated to reflect the change.

    magius2244

    (@magius2244)

    Has there been any update to this issue as of yet?

    Thread Starter Vince

    (@vincentrich)

    This has not been fixed in WordPress 2.6.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WordPress 2.5 wp_list_pages Errors’ is closed to new replies.