WordPress: Custom Page Listing


/ Published in: PHP
Save to your folder(s)

This custom loop will list all sub pages from a parent page including grand childrens. Example use: Car models listing


Copy this code and paste it in your HTML
  1. <ul class="list">
  2.  
  3. <?php $pageChildren = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
  4. <?php if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?>
  5. <li>
  6. <div class="left">
  7. <?php echo the_post_thumbnail($pageChild->ID); ?>
  8. <div class="hover">
  9. <a href="<?php echo get_permalink($pageChild->ID); ?>">Details</a> <a href="#">Request a Quote</a>
  10. <span class="small">MSRP: <?php echo get_post_meta($pageChild->ID,'msrp', true); ?></span>
  11. </div>
  12. </div>
  13. <div class="right">
  14. <h5><?php echo $pageChild->post_title; ?></h5>
  15. <p><?php echo get_post_meta($pageChild->ID,'small-desc', true); ?></p>
  16. <div class="links">
  17. <?php
  18. $grandChildren = wp_list_pages('title_li=&child_of='.$pageChild->ID.'&echo=0');
  19. if ($grandChildren) { ?>
  20. <ul class="links">
  21. <?php echo $grandChildren; ?>
  22. </ul>
  23. <?php } ?>
  24. </div>
  25. </div>
  26. <div class="clearfix"></div>
  27. </li>
  28. <? endforeach; endif; ?>
  29.  
  30. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.