Forums

[resolved] Child / Parent relationship (7 posts)

  1. hoss9009
    Member
    Posted 2 years ago #

    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

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    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.

  3. hoss9009
    Member
    Posted 2 years ago #

    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. :)

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  5. hoss9009
    Member
    Posted 2 years ago #

    Umm... I'm not sure I follow... could you break down what you mean by "provide a page id"?
    Thank you so much.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  7. hoss9009
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic