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.

Let's say I have a website about different types of cars. The structure is a little like this:

-Home
-Cars (shows a submenu with a list of cars, ie Volvo 850, Porsche 911 )
 -Volvo 850 overview (the page you get when you click Volvo 850 on the Car page)
 -Volvo 850 tech spec (the three Volvo pages are shown as submenu links on any Volvo page)
 -Volvo 850 pictures
 -Porsche 911 overview
 -Porsche 911 tech spec
 -Porsche 911 pictures

What's the best way of doing this? I guess what I'm asking is how to automatically make the Cars page list the different Cars, and link to the overview page and not the others. And then on the individual car pages, have more sub-menus for overview, tech spec, and pictures page.

I could have a structure like this:

-Cars (shows a submenu with a list of cars, ie Volvo 850, Porsche 911 )
 -Volvo 850
  -Volvo 850 overview (the page you get when you click Volvo 850 on the Car page)
  -Volvo 850 tech spec (the three Volvo pages are shown as submenu links on any Volvo page)
  -Volvo 850 pictures

.. but I don't want that intermediate Volvo 850 page to show, because there would be nothing on it.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Referencing the wp_list_pages function reference

You'll probably need to use the second structure you listed, with one change:

-Cars (shows a submenu with a list of cars, ie Volvo 850, Porsche 911 )
 -Volvo 850 overview (the page you get when you click Volvo 850 on the Car page)
  -Volvo 850 tech spec (the three Volvo pages are shown as submenu links on any Volvo page)
  -Volvo 850 pictures

I think the following may work, although it might show all descendants (rather than immediate children only):

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

Your statement

And then on the individual car pages, have more sub-menus for overview, tech spec, and pictures page.

Seems contradictory to not wanting an 'intermediate' page, since you said you want the "overview" page to be what you land on when clicking on a car model on the cars page. If you just want all pages related to the Volvo 850 to have a listing of Volvo 850 pages (for instance, in the sidebar), you could possibly use this:

<?php 
// use wp_list_pages to display parent and all child pages all generations (a tree with parent)
$parent = 93;
$args=array(
  'child_of' => $parent
);
$pages = get_pages($args);  
if ($pages) {
  $pageids = array();
  foreach ($pages as $page) {
    $pageids[]= $page->ID;
  }

  $args=array(
    'title_li' => 'Tree of Parent Page ' . $parent,
    'include' =>  $parent . ',' . implode(",", $pageids)
  );
  wp_list_pages($args);
}
?>
share|improve this answer

Hi @cannyboy:

You asked a very similar and related question in "Same Custom Fields spanning several pages?" and I think your answer is really the same:

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.