Support » Fixing WordPress » Gettin child page links

  • Resolved maanse


    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…

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think it can be done directly using Menus .

    that would be a lot of menus to create.



    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.

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

    Ill have a read, thanks again.



    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Gettin child page links’ is closed to new replies.