• Hello,

    I’m fairly new to WordPress and this is definitely my first experience using it as a CMS system. I’ve figured out pages, posts, etc., and mostly everything is working. I do, however, have a couple of questions:

    The site is at: here

    Navigation: I’ve used permalinks for my horizontal menus and wp_list_pages to generate the left vertical menu. What is displayed here depends on what horizontal link is clicked, with the children of that link being displayed.

    My problem is dealing with 2nd and 3rd level children. For example, if you go to newcomers you will only see one level of pages. If you then click on Quick Search in the left menu, you can see that several of these “child” pages on the left have “children” of their own, and now they are all displayed.

    The way I would like this to work is, when you click on Quick Search you then ONLY see the children of Quick Search in the left menu.

    I can see how I could write some code to do this manually by targeting the $post->id, but then if the client adds child pages to any of these, someone will have to modify the code. If possible I would like this to be fully automatic.

    Is this possible, and how do I go about it?

    The code I’ve used for my menu is:

    <ul>
    	<?php
    	if($post->post_parent)
    		$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=2");
    	else
    		$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
    
    	if ($children) {
    		echo $children;
    	} else {
    		wp_list_pages ("include=72, 129, 175&title_li=");
    	}	
    
    	?>
    </ul>

    Thanks in advance,

    Matt

Viewing 4 replies - 1 through 4 (of 4 total)
  • I presented this on another thread but the OP claimed it didn’t work but it works fine at least in sidebar.php of the WordPress Default Theme–so maybe you can use it:

    <?php
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>' );
    if (is_page( )) {
      $page = get_query_var('page_id');
      if ($post->post_parent) {
        $page = $post->post_parent;
      }
      $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      if ($children) {
        $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>');
      }
    }
    echo $output;
    ?>

    For the record, Michael’s code is what I’ve used on three or four different client sites, and it works fine.

    Hello !

    I really want to use this code for my website.

    I know that I have to put it in “sidebar.php”.

    But I don’t know what part of the code I have to change in the code to adapt it for my website.

    The address : https://gogoackman.jed.st/

    I want to display only “Accueil” and its first generation child Pages.

    Thank you ! ;^)

    help please !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problems with pages and navigation’ is closed to new replies.