I have a home page with navigation menu, consisting of Tennis, Polo, Hiking and Cricket (which are parent pages on a template called Sport pages), as an example. When I add a page, e.g Swimming, it displays on the menu - all good.

When I click on the Tennis link in navigation it takes me to the home page of Tennis, where the main menu still displays.

Then the Tennis home page has a sub-menu consisting of Dates, Events, and Players (child pages on a template called Sport Sub Pages), which displays the content of the Tennis home page with all the sub-menu items, landing on the Date page, as it is the first sub-menu item.

However, when I click on the sub-menu item on the Tennis page Events, it goes to the events page, but the sub-menu disappears because it loses the link to the parent page.

Example of my code in the parent template (e.g Tennis parent page):

$id = the_ID();
while ( have_posts() ) : the_post();
  $args = array(
      'post_type' => 'page',
      'post_parent' => $id,
      'order' => 'ASC',
      'orderby' => 'menu_order',
      'posts_per_page' => -1
  $sport_parent= get_posts($args);

  foreach ($sport_parent as $sp){
    echo "<a href=" . $sp->guid . "> ". $sp->post_title . "</a>";


This displays the Tennis parent page with all the children in a menu.

However when I change to another link of the child menu, the menu disappears. I have tried many variations in the Sport Sub page to keep the sub-menu when I change pages. I even tried to use the slug in the url and compared it to the permalink, tried IDs but they won't work because as soon as I go to another child page then the connection of the ID to parent page is lost.

Any ideas what other approaches I could try - to do on the Sport Sub page to keep the sub-menu when I click on another link of the child menu?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.