Show child pages in a child page? (4 posts)

  1. evenglen
    Posted 8 years ago #

    I got this code from http://www.atourworst.org:

    post->post_parent) ) { $parent = $wp_query->post->ID; } else { $parent = $wp_query->post->post_parent; } wp_list_pages(”title_li=&child_of=$parent”); ?>

    and i fixed it to be this:

    <?php if ($post->post_parent) { $parent = $wp_query->post->ID; } else { $parent = $wp_query->post->post_parent; } wp_list_pages('title_li=&child_of=$parent'); ?>

    its supposed to show the child pages on the child pages like this:

    if on about page -
    ask me

    if on ask me page -
    ask me

    iuno if i sound normal but that the best way i can explain it. can someone help me out or correct me or something? id really appreciate it. thanks.

  2. evenglen
    Posted 8 years ago #

    oh yea, here is the URL to the post I found it on in case it helps:


  3. Kafkaesqui

    Posted 8 years ago #

    The code's logic is backwards:

    if ($post->post_parent) {
     $parent = $post->post_parent;
    } else {
     $parent = $post->ID;

    So when there's a Page parent (defined in 'post_parent' column), $parent is assigned its ID; otherwise the current Page is (assumed to be) a parent and its ID is assigned to $parent.

    Notes: There is a change to double-quotes for the wp_list_pages() arguments -- a variable inside single quotes is read by PHP literally ('$parent' rather than '10'). And since we're originally working off the $post object, there's no reason to switch to $wp_query.

  4. evenglen
    Posted 8 years ago #

    oh thankies muchly. :) i shall try it out and see how it goes.

Topic Closed

This topic has been closed to new replies.

About this Topic