• Resolved hoss9009

    (@hoss9009)


    ok so I’m wanting to design a site that will have children to parent pages. The normal nav will be in a “index_sidebar.php”.
    On top of that, I will want the links of the children to appear on a “inside_sidebar.php”. (inside “pages” will look different than the

    To further explain my, I’ve created a framework.
    Here’s a pic of what I’m trying to do.
    The blue is the parent nav and the red is WHERE the children nav will be (ignore the stuff that is there now).

    Only 3 pages have children, so I’m wondering if there’s a cool/easy WP-php tag I could throw where the children nav would be that would ask the parent nav “if there's children, show here; if not, show nothing and allow the 'recent comment' box to move up in place“.

    It may be a stretch asking for that, but I thought check.
    Any help would be MUCH appreciated.

    -Eric

Viewing 6 replies - 1 through 6 (of 6 total)
  • There isn’t a tag but it can be done. Try adding the following to your functions.php file:

    // show all children of a post or page
    function ShowChildren($curr_post) {
    	$my_children = '';
    	if(!$curr_post->post_parent) $my_children = wp_list_pages("title_li=&child_of=".$curr_post->ID."&echo=0");
    	if ($my_children !='') {
    		echo '<div class="sub_pages"><h3>Pages in This Section</h3><ul>'."\n";
    		echo $my_children;
    		echo "</ul></div>\n";
    	}
    }

    Then use <?php if (function_exists('ShowChildren')) ShowChildren($post);?> where you want your sub-pages to show. Bear in mind that this has to be within The Loop, though.

    Hope that helps.

    Thread Starter hoss9009

    (@hoss9009)

    Im nearly 100% that the children navigation won’t be in the loop… how awful is it if it’s not in the loop?

    PS. I’m well versed in PHP… could you explain why it would need to be in the loop? I just want to learn. ??

    In theory, it would work if you could provide it with a page or post id.

    Thread Starter hoss9009

    (@hoss9009)

    Umm… I’m not sure I follow… could you break down what you mean by “provide a page id”?
    Thank you so much.

    The code above starts with the parent page id. Otherwise, how does it know what child pages to show?

    Thread Starter hoss9009

    (@hoss9009)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Child / Parent relationship’ is closed to new replies.