• Hello. I have a situation that seems a bit more complicated than your average List Subpages technique. Also, the first answer by Roger at this forum thread seems to come close.

    My client’s site has a typical navigation with subnav:

    A pages:

    • A
    • A1
    • A2
    • A3

    B pages:

    • B
    • B1
    • B2
    • B3

    C pages:

    • C
    • C1
    • C2
    • C3

    I need the sidebar of any “A” page (the parent and its children) to show ONLY the “A” li and the “A” nested ul.

    Likewise for any “B” page or any “C” page.

    This is what I have so far:

    <div id="sidebar">
    
    <?php
    // let's generate info appropriate to the page being displayed
    if (is_page()) {
            // we're looking at a static page.  Which one?
            if (is_page('2') || $post->post_parent) {		// About Us page.
                 echo "<ul style='margin-bottom: 0px;'>";
    			    wp_list_pages('title_li=&include=2&sort_column=menu_order&depth=1&child_of=0');
    			 echo "</ul>";
    
    			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) {
    				echo "<ul style='margin-top: 0px;'>";
    				echo $children;
    				echo "</ul>";
    			}
            } elseif (is_page('60') || $post->post_parent) {		// Menu/Wine List page.
                 echo "<ul style='margin-bottom: 0px;'>";
    			    wp_list_pages('title_li=&include=60&sort_column=menu_order&depth=1&child_of=0');
    			 echo "</ul>";
    
    			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) {
    				echo "<ul style='margin-top: 0px;'>";
    				echo $children;
    				echo "</ul>";
    			}
            } elseif (is_page('44') || $post->post_parent) {		// Private Dining page.
                 echo "<ul style='margin-bottom: 0px;'>";
    			    wp_list_pages('title_li=&include=44&sort_column=menu_order&depth=1&child_of=0');
    			 echo "</ul>";
    
    			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) {
    				echo "<ul style='margin-top: 0px;'>";
    				echo $children;
    				echo "</ul>";
    			}
            } elseif (is_page('26') || $post->post_parent) {		// Contact Us page.
                 echo "<ul style='margin-bottom: 0px;'>";
    			    wp_list_pages('title_li=&include=26&sort_column=menu_order&depth=1&child_of=0');
    			 echo "</ul>";
    
    			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) {
    				echo "<ul style='margin-top: 0px;'>";
    				echo $children;
    				echo "</ul>";
    			}
            }
    }
    ?>

    There’s a lot of redundancy here, I know. (If you have suggestions on how to pare this down, too, I’d appreciate it.)

    But the main problem seems to be with this:
    elseif (is_page('2') || $post->post_parent)
    and
    elseif (is_page('60') || $post->post_parent)

    I need to combine the capability of wp-list-pages technique and the “list subpages on the subpage” technique, so that the title (parent LI) of each subnav is also a link. Otherwise, the way I’m doing it above, the pages for ’60’ show the subnav for ’60’ but the parent LI for ‘2’. Like so:

    A pages:

    • A
    • A1
    • A2
    • A3

    B pages:

    • A
    • B1
    • B2
    • B3

    C pages:

    • A
    • C1
    • C2
    • C3

    Sorry for the long post. Let me know if you have more questions, or if there is another place you can point me to.

    Thanks!
    STAN

  • The topic ‘Listing subpages only for certain sections’ is closed to new replies.