Good day all. I have this code that I found/edited which displays all the child pages and an excerpt of each page too. (I’ve placed the code in a custom template)
It works pretty good, but I’d like some help cleaning up and optimizing the code, if at all possible with the help of some of the WordPress programming gurus and experts.
I believe the code can be optimized, but if it already is, then could someone also help add the functionality of having the child pages listed with the most recent at the top.
In the code below, you’ll see “ORDER BY menu_order”, but when I change that to date, ASC or DESC for instance, nothing will display on the page.
<?php $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 ); ?> <h2 class="subpagetitle"><a href=" <?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title=" <?php echo $pageChild->post_title; ?>"> <?php echo $pageChild->post_title; ?></a> </h2> <?php $your_custom_field = get_post_meta($pageChild->ID, 'your_custom_field', $single = true); the_excerpt();?> <?php endforeach; endif; ?>
To all and everyone who tries to help with this, I and future readers thank you for your contributions.
- The topic ‘List Child Pages and Excerpts’ is closed to new replies.