Display child info ONLY on related parent page (3 posts)

  1. killputer
    Posted 7 years ago #

    I searched around and found some code that allowed me to pull the title, excerpt, and an image using a custom field of a "subsection" (child) on a "section" (parent) page. The problem I am having is that when add this loop to the pages.php template it spits out the subsection (child) snippets on EVERY section page. What I am trying to accomplish is to have one the original parent show the snippets from it's child(ren). Each parent will have different children, and the ones without will show none.

    Here is what I am currently using:

    <?php $pageChildren = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent =7 AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
    <?php if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?>

    Any help would be greatly appreciated. thanks.

  2. tgiokdi
    Posted 7 years ago #

    eh, I'm likely going the long way around this, but you can set up custom templates for each of your categories or pages :


  3. killputer
    Posted 7 years ago #

    I created a variable called "$post_ID" and set it to the current page's ID.
    I then replaced the "7" with $post_ID - This will ensure that you always have the right page ID. Seems to be working now with only one template.

Topic Closed

This topic has been closed to new replies.

About this Topic