Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] WordPress child/parent relationship

  • This topic is empty.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #25178
    hoss9009
    Member

    Disclaimer: I know this isn’t a WordPress site, but I’m posting this in the PHP section because my question may require a some advanced php scripting… and WordPress. :D

    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 http://img200.imageshack.us/i/capturerwb.jpg/ 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:

    Code:
    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

    #59293
    TheDoc
    Member

    The WordPress Codex is your best friend ever!

    "This code will show the child pages, and only the child pages, when on a parent or on one of the children. This code will not work if placed after a widget block in the sidebar."

    Code:
    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) { ?>

    Clicky for source

    #59191
    hoss9009
    Member

    I wasn’t planning on placing it in a widget block… am i good to go w/ this you think?
    I’ll try it out today, if I have a chance.
    THANK YOU!

    #59196
    apostrophe
    Participant

    I just checked an old client site and this was exactly the code I used. WordPress will even throw in the classes for you for highlighting current pages etc.
    So yes, you shouldn’t have any problems.

    #59538
    hoss9009
    Member

    GOT IT!!! IT WORKED!!!!

    #61917
    hoss9009
    Member

    Ok, so the code provided in this thread is AWESOME!

    But….

    The title of the parent page is now what I’m after..

    Here’s my current code:

    Code:
    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) { ?>

    My problem is <?php the_title(); ?>. I want the title of the parent to show instead of the child. This way when choosing a child, the parent title exists the same in the H3 that i have there.

    I know there’s gotta be something like post_parent_title, but I’m just not sure.

    Any ideas? Help!

    Thanks!

    #61957
    hoss9009
    Member
    #61828
    hoss9009
    Member

    Ok… another problem.

    Whem I’m on the parent, I want the parent title to show up in my nav, but it’s not.
    This is the code I’m using.

    Code:
    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) { ?>

    post_parent) {
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>

    Here’s a link to the site itself… http://www.ericdmunoz.com/dhe/summer-programs/

    You’ll notice that there’s a spot for an h3, but it won’t show up until you click on a child.

    Any ideas how to have my cake and eat it, too?

    #61833
    TheDoc
    Member

    I dig the site! Looks great.

    I was just about to post some code, but then realized you already had it in there. It has to be something very simple, I feel like I’m overlooking something.

    #61837
    hoss9009
    Member

    Thank you…
    PLEASE let me know if you come up w/ something….
    Maybe a "parent_title" ?

    #61838
    hoss9009
    Member

    Ok…. GOT IT!!!!!!!!!!!!!!!!!!

    Code:
    post_parent);
    echo $parent_title;
    ?>

    I just took out the "if" statement…

    #50007
    jtdesign00
    Member

    What about if you wanted to make the list have a dynamic ‘current’ class?

    Thanks in advanced!

    #107570
    shovan
    Member

    How do you get parent page url? This is what I have


    if($post->post_parent) {
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    $titlenamer = get_the_title($post->post_parent);
    }

    else {
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    $titlenamer = get_the_title($post->ID);
    }
    if ($children) { ?>









    #107571
    shovan
    Member

    Found the solution :)


    if($post->post_parent) {
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    $titlenamer = get_the_title($post->post_parent);
    }

    else {
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    $titlenamer = get_the_title($post->ID);
    }
    if ($children) { ?>




    Thanks
    Shovan

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Back End’ is closed to new topics and replies.