0

Here is my website structure(wordpress pages)

 - HOME - - Tutorial - + PHP Tutorial + + Photoshop Tutorial + + Css Tutorial + + HTML Tutroial + - news - + November + September + May + April - about - - contact - 

How do I have the output just the pages which have children pages? so when I click tutorial page, the tutorial page has following list. (but pages list stays static when click subpages.

  • Tutorial -
    • PHP Tutorial +
    • Photoshop Tutorial +
    • Css Tutorial +
    • HTML Tutroial +

I am using this code, but this only displays all children pages no parent.

<?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=1"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> 

1 Answer 1

0

Do you want to list only the pages with children? I'm not sure to understand well what you want to do :( If I'm right, you'll have to do something like this with get_pages() and generate your listing manually after:

// First get all pages $pages = get_pages(); // Then, get page IDs if ($pages) { $pageids = array(); foreach ($pages as $page) { // Test if page has children if ( get_pages( 'child_of=' . $page->ID ) ) { // Save it if it's OK $pageids[]= $page->ID; } } $args = array( 'title_li' => 'Pages with at least one child', //TODO: add yout display parameters here ); wp_list_pages($args); } 

I think this could work!

3
  • Hmm, I think your problem is another one, but, with get_pages() you should do what yout want. Look at this example: codex.wordpress.org/Function_Reference/… Commented Mar 25, 2013 at 23:34
  • thanks a lot. It prints all pages ... but only need itself and its children pages. thanks for the link Commented Mar 25, 2013 at 23:59
  • one more question, how can I make it static, it shows nothing when I click the 2nd level , How to make it only shows the itself and all children -Static? thanks Commented Mar 26, 2013 at 1:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.