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.

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 } ?>
share|improve this question

1 Answer 1

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!

share|improve this answer
    
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/… –  MavBzh Mar 25 '13 at 23:34
    
thanks a lot. It prints all pages ... but only need itself and its children pages. thanks for the link –  olo Mar 25 '13 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 –  olo Mar 26 '13 at 1:53

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.