Support » Fixing WordPress » child nav on parent page (which is blog)

  • cmdshiftdesign

    (@cmdshiftdesign)


    Have sub nav within my header.php file as such:

    [code moderated – use the pastebin for any code over the forum limit of 10 lines]

    this works perfect – except ONE thing.

    I have by Posts to be on a page named “Events” and this Page is a Child of the Main Navigations “About”

    Well, this “Events Page” does show in the sub-nav when “about” is clicked, and following that link does show that page with the Posts — but once you are ON that page, the sub-nav no longer displays… even though the index.php is pulling the EXACT same header.php file.

    I’m guessing this has something to do with this Page now being seen as a Blog… Help? Anyone?

Viewing 3 replies - 1 through 3 (of 3 total)
  • tresinvolved

    (@tresinvolved)

    So it is seeing the “Events” Page as a blog?

    It might help to know which conditional is getting hit in your initial if/else. Just add some test echo statements:

    if ($post->post_parent) {
    	//get the parrent and see if it'a a top page (has no parent)
    	$parent = get_page($post->post_parent);
    	if ($parent->post_parent) {
                     echo "A"; /* Testing */
    		//if it's not a top page, then his parent should be
    		$children = wp_list_pages('title_li=&child_of=' . $parent->post_parent . '&echo=0');
    	} else {
                     echo "B"; /* Testing */
    		$children = wp_list_pages('title_li=&child_of=' . $post->post_parent . '&echo=0');
    	}
    } else {
            echo "C"; /* Testing */
    	$children = wp_list_pages('title_li=&child_of=' . $post->ID . '&echo=0');
    }

    Might also help to echo the $post->ID to see if you’re viewing the ID of the Events page, or something else.

    Also, I’m not sure about this part of your code (in two places):

    <li><a>">

    What is the quotation mark for?

    cmdshiftdesign

    (@cmdshiftdesign)

    we’re getting the C back.

    tresinvolved

    (@tresinvolved)

    Okay, so can you just manually set the $post->ID in the wp_list_pages function (in the section that echoed “C”) to be that of the About Page? Does that work?

    I’m guessing Events is returning a blog post for $post->ID and not the Events Page ID. Hard to know for sure without knowing what your Events Page template is.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘child nav on parent page (which is blog)’ is closed to new replies.