[resolved] Gettin child page links (6 posts)

  1. maanse
    Posted 3 years ago #

    Hi guys,

    Im using the following query on some of my 'parent' pages to show the links to all of its child pages:

        $child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
        <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
        <div class="child-thumb">
          <a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
        <?php endforeach; endif;

    That works fine but what im wondering is how i could adapt that code to show all the child pages from the parent actually on the child page.

    So when i go to a child page it shows the links for its siblings...

  2. techonda
    Posted 3 years ago #

    I think it can be done directly using Menus .

  3. maanse
    Posted 3 years ago #

    that would be a lot of menus to create.

  4. wpismypuppet
    Posted 3 years ago #

    You are over complicating this... it's nice to write your own functions, of course! That's how we learn... but why reinvent the wheel? Look into wp_list_pages():


    Read through to understand the function and parameters, but pay special attention to the section labeled "List subpages even if on a subpage" as it does exactly what you are looking for.

  5. maanse
    Posted 3 years ago #

    Thanks for this, your right about over complicating. Didnt know this function existed...

    Ill have a read, thanks again.

  6. wpismypuppet
    Posted 3 years ago #

    No problem... in all my years of coding I've come to realize that 9 times out of 10 there's already a function to accomplish what I need done. And if it doesn't do exactly what I want, at least I have a good starting point to work from :). Glad I could help...

    If this topic has been resolved, please mark it appropriately so other people know you are all set. Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.