Using query posts to list child pages
-
I’m working on a custom template for a page which has a number of child pages.
I’m trying to create an unordered list of sub-pages on the parent page. I’ve already installed a plugin that lets me add Excerpts to pages, and I want to use the excerpt to display a brief summary of each sub-page alongside the page titles. Once I have it working with the Excerpt, I plan to add thumbnail images by using custom fields for each sub-page.
First I tried using
wp_list_pages
https://codex.www.ads-software.com/Template_Tags/wp_list_pages#List_Sub-Pages to call up the sub-pages of the parent page but this only displayed a list of the sub-pages. It seems I need to use the Loop to call up the Excerpt, and I couldn’t getwp_list_pages
working with the loop.So instead I’ve tried using
query_posts
https://codex.www.ads-software.com/Template_Tags/query_posts#Retrieve_a_Particular_Page. I’ve been successful displaying one sub-page title and its excerpt (I’ll deal with the custom field later), but thequery_posts
seems to only let me call up one specific page rather than all of the sub-pages.I don’t really mind if I have to manually add the page titles to the
query_posts
tag in the template, though obviously it would be ideal if I could somehow call up all the sub-pages and still display the excerpt and custom field alongside the page titles (this only seems possible within the Loop).The code I’m currently using is below (the parent page is called “festivals” and the first sub-page is called “second-test-festival”). The main thing I want to know is whether it’s possble to add a second
pagename
to thequery_posts
tag.If there are other ways of acheiving what I want then I’d love to hear them too. Thanks!
<?php query_posts('pagename=festivals/second-test-festival'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li> <span class="headline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span> <?php the_excerpt(); ?> </li> <?php endwhile; ?> </ul>
- The topic ‘Using query posts to list child pages’ is closed to new replies.