WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#11026 closed defect (bug) (duplicate)

wp_list_pages include and depth argument conflict

Reported by: pnts Owned by: pnts
Milestone: Priority: normal
Severity: normal Version: 2.8.5
Component: Template Keywords:
Focuses: Cc:

Description

When using wp_list_pages with both the depth and include arguments, child pages will not display at depths equal to or greater than 2. If you replace the include with exclude, child pages display as expected.

So, in this example, I have a large number of top-level pages, and I just want to include 4 pages, plus their children, in my global navigation, I'd use:

<?php wp_list_pages('title_li=&depth=2&include=12,26,22,47); ?>

Except that child pages are not rendered in this view. Instead, if I use the same approach but *exclude* every page that shouldn't be displayed, then child pages are rendered:

<?php wp_list_pages('title_li=&depth=2&exclude=1,2,3,17,18,27,43,46,51,55); ?>

I've noticed this with in the WP 2.8 versions, have not tested it for previous releases. This is replicable with plug-ins disabled and using the default theme.


Change History (3)

comment:1 @scribu6 years ago

  • Component changed from General to Template
  • Keywords needs-patch added; wp_list_pages removed
  • Milestone changed from Unassigned to 2.9
  • Version set to 2.8.5

comment:2 @filosofo6 years ago

  • Keywords wp_list_pages added

Replying to pnts:

So, in this example, I have a large number of top-level pages, and I just want to include 4 pages, plus their children, in my global navigation, I'd use:

<?php wp_list_pages('title_li=&depth=2&include=12,26,22,47); ?>

Unfortunately, that's not what "include" means. "include" specifies which IDs to show. What you're looking for is something like "include_tree", which doesn't yet exist as an option. See #9232, a ticket proposing this enhancement.

One simple way to do this is hard-code the list elements of pages 12, 26, 22, and 47, and within each list item call wp_list_pages() each call specifying that page in the "child_of" parameter.

E.g:

<ul>
   <?php foreach( array(12,26,22,47) as $page_id ) : ?>
   <li class="page_item page-item-<?php echo $page_id; ?>">
      <a title="<?php echo esc_attr(get_the_title($page_id)); ?>" href="<?php echo get_permalink($page_id); ?>"><?php echo get_the_title($page_id); ?></a>
      <ul>
      <?php wp_list_pages('title_li=&depth=2&child_of=' . $page_id); ?>
      </ul>
   </li>
   <?php endforeach; ?>
</ul>

This ticket should probably be closed as a duplicate of #9232.

comment:3 @nacin5 years ago

  • Keywords needs-patch wp_list_pages removed
  • Milestone 2.9 deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.