Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using wp_list_pages('title_li=') on my site.

Some of my pages do have subpages, however I don't want to list them unitl I'm on an actual parent page that has subpages.

So imagine my front-page:

— About Us
— Gallery
— Kitchen
— Disclaimer

When clicking on Gallery (and Gallery has two subpages) I want them to be listed as well.

— About Us
— Gallery
  — Subpage 1
  — Subpage 2
— Kitchen
— Disclaimer

How am I going to do this with the wp_list_pages() function?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

This would probably be better achieved using CSS. First, you hide all .children:

.page_item .children {
  display: none;
}

Then, you show the current_page_item's children:

.current_page_item .children {
  display: block;
}
share|improve this answer

try the following:

$output = wp_list_pages(depth=1);

expl: depth (integer) This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).

    0 (default) Displays pages at any depth and arranges them hierarchically in nested lists
    -1 Displays pages at any depth and arranges them in a single, flat list
    1 Displays top-level Pages only
    2, 3 … Displays Pages to the given depth 

For mor info can have a look here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.