loop showing only grandchildren of ancestor pages
-
i have a db query using get_results that is successfully pulling all child pages of a particular parent page.
i am having trouble converting the code into a new loop that pulls all grandchildren pages of that same ancestor page.
here is the code that i have working for child pages:
<?php $results = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish'"); $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY ID", 'OBJECT'); ?> <?php if (!empty ( $child_pages )) : ?> <? endif; ?> <h3 class="category-heading"><?php the_title(); ?></h3> <div id="featured-container"> <div class="flexslider"> <ul class="slides"> <?php $i = 0; if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?> <li> <?php $post_image_id = get_post_thumbnail_id($pageChild->ID); if ($post_image_id) { $sliderBg = wp_get_attachment_image_src( $post_image_id, 'large', false); if ($sliderBg) (string)$sliderBg = $sliderBg[0]; } ?> <a class="slider-img" href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>" style="background: url(<?php echo $sliderBg ?>) top left no-repeat;"></a> <div class="featured-box"> <h2><a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a></h2> <p><?php echo $pageChild->post_excerpt; ?></p> </div><!--featured-box--> </li> <?php endforeach; endif; ?> </ul><!-- slides --> </div><!-- flexslider --> </div><!-- featured container --> <?php endif; ?> <?php endwhile; endif; ?>
i have tried some conventional attempts to place a loop within a loop, but the get_results approach is giving me trouble.
any help is appreciated!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘loop showing only grandchildren of ancestor pages’ is closed to new replies.