Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#5708 closed defect (bug) (invalid)

wp_list_pages() will not list subpages by ID if the parent is not included.

Reported by: chippeterson's profile chippeterson Owned by: hailin's profile hailin
Milestone: Priority: normal
Severity: normal Version: 2.3
Component: General Keywords: list subpages
Focuses: Cc:

Description

Here is a simple example.

If the parent of page 23 is not in the list the page 23 will not pe displayed. Here is the code, I tested 5 times:

<?php
wp_list_pages('include=5,9,13,23&title_li=<h2>' . ('Poetry') . '</h2>' ); ?>

This will display all 4 pages because 13 is a parent of 23.

<?php
wp_list_pages('include=5,9,23&title_li=<h2>' . ('Poetry') . '</h2>' ); ?>

This will display only 5 and 9 because 13, the parent of 23, is not in the list.

So, you can not list subpages if their parent is not in the list.

Change History (3)

#1 @hailin
18 years ago

  • Owner changed from anonymous to hailin
  • Status changed from new to assigned

#2 @hailin
18 years ago

  • Resolution set to invalid
  • Status changed from assigned to closed

This is not an issue with the latest wporg builds.
I've tested with similar page structure, and it appears to be fine.

In your case, 23 should be displayed at the very end, because it is an "orphan page" - pages whose parents do not exist.

Note that the comment for walk() function has:

  • max_depth = -1 means flatly display every element
  • max_depth = 0 means display all levels
  • max_depth > 0 specifies the number of display levels.

so as long as 0 is passed in, every page will be displayed, regardless of it is an orphan page or not. However, if 0 is not passed in, orphan page will be skipped.
By default, 0 is used in wp_list_pages().

Below is the logic in the code where the orphan page is handled, just FYI.

wp-includes/classes.php
function walk( $elements, $max_depth)
/*

  • if we are displaying all levels, and remaining children_elements is not empty,
  • then we got orphans, which should be displayed regardless

*/
....

#3 @lloydbudd
18 years ago

  • Milestone 2.7 deleted
Note: See TracTickets for help on using tickets.