/ Published in: PHP
This custom loop will list all sub pages from a parent page including grand childrens. Example use: Car models listing
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<ul class="list"> <?php $pageChildren = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?> <?php if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?> <li> <div class="left"> <?php echo the_post_thumbnail($pageChild->ID); ?> <div class="hover"> <a href="<?php echo get_permalink($pageChild->ID); ?>">Details</a> <a href="#">Request a Quote</a> <span class="small">MSRP: <?php echo get_post_meta($pageChild->ID,'msrp', true); ?></span> </div> </div> <div class="right"> <h5><?php echo $pageChild->post_title; ?></h5> <p><?php echo get_post_meta($pageChild->ID,'small-desc', true); ?></p> <div class="links"> <?php $grandChildren = wp_list_pages('title_li=&child_of='.$pageChild->ID.'&echo=0'); if ($grandChildren) { ?> <ul class="links"> <?php echo $grandChildren; ?> </ul> <?php } ?> </div> </div> <div class="clearfix"></div> </li> <? endforeach; endif; ?> </ul>