Forums

How to still get the menu displayed in child pages (5 posts)

  1. mlnosp
    Member
    Posted 3 years ago #

    Hello,

    I am using two menues: one in the header of the each pages to display the first level menu (without children pages). The second menu gets only displayed on the left sidebar if there are children in a page (a page in a page). For this second level menu I use the following code in sidebar.php:

    global $post;
    $page_id = $post->ID;
    wp_list_pages("child_of=$page_id&title_li=");

    Now my problem is that when I click on a second level page (the page in a page) the menu on the left side disappears but I would like to keep it, how can I do that ?

    Many thanks

  2. MadsK
    Member
    Posted 3 years ago #

    You have to create a page template for the child pages which uses

    wp_list_pages("child_of=xx&title_li=");

    Change xx with the ID of the page which has the children pages.

    This does require you to create a new template for each children page which is not under the same parent.

  3. MadsK
    Member
    Posted 3 years ago #

    I haven't tried this my self you might also be able to use

    wp_list_pages("child_of=$post->post_parent&title_li=")

    Again i haven't tried this argument, but i've read it should work :) Then you don't have to create new templates but just one! :)

  4. mlnosp
    Member
    Posted 3 years ago #

    Thank you MadsK for the great idea of using post_parent. Thank to you I could solve my problem like this without requiring any extra template pages:

    if( $post->post_parent )
    		$page_id = $post->post_parent;
    	else
    		$page_id = $post->ID;
    	wp_list_pages("child_of=$page_id&title_li=");
  5. MadsK
    Member
    Posted 3 years ago #

    I'm glad i could help :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.