Question

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.

Was it helpful?

Solution

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);
}
?>

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top