Community Forums › Forums › Archived Forums › Design Tips and Tricks › Displaying Child Pages on Parent Page (with thumbnails)
- This topic has 6 replies, 2 voices, and was last updated 8 years, 9 months ago by carrieoke13.
-
AuthorPosts
-
December 5, 2014 at 2:41 pm #133729carrieoke13Participant
I'm trying to create a page template that displays all child pages on a parent page (displayed using the featured image from the page and the page title). I've got this function so far, but it's only showing the first child page. What am I missing?
add_action( 'genesis_entry_content', 'wpb_list_child_page', 5 ); /** * This function adds an unordered list of child pages right before the post content in Genesis. * * @global object $post The current post object. */ //* display sub pages with thumbnails *// function wpb_list_child_page() { global $post; //query subpages $args = array( 'post_parent' => $post->ID, 'post_type' => 'page' ); $child_query = new WP_Query( $args ); if ( $child_query->have_posts() ) { while ( $child_query->have_posts() ) { $child_query->the_post(); } ; } else { // no posts found wp_reset_postdata(); } if ( $image = genesis_get_image( 'format=url&size=medium' ) ) { printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); printf ('<h3><a href="%s">%s</h3>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() ); printf( '<a href="%s"><img src="http://www.ravelry.com/images/shopping/buy-now.gif" border="0"/>', get_field('ravelry_buy_now_link') ); printf('</div>');} } genesis();
Thanks for any help!
http://identitywebandphoto.com/abby/wordpress/designs/accessories/December 5, 2014 at 4:00 pm #133738Ren VenturaMemberI went through and modified the code you had. There were some issues so I cleaned it up and made some necessary adjustments. This should work for you. Just note that when I edited the code, I did not include the genesis() function at the end so you'll need to add that if using it on a page template.
https://gist.github.com/EngageWP/50eca14875dc985e904b
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
December 5, 2014 at 4:23 pm #133740carrieoke13Participantthank you SO much. It is working now, except that it is only showing the 5 most recent posts. Is there a way to have the page display all child pages? Here's an example of it working, showing the most recent 5: http://identitywebandphoto.com/abby/wordpress/designs/sweaters/
December 5, 2014 at 4:43 pm #133742Ren VenturaMemberJust add the posts_per_page argument to the query. I updated the gist.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
December 5, 2014 at 4:47 pm #133744carrieoke13Participantthank you so so much! Works beautifully.
December 5, 2014 at 4:52 pm #133745Ren VenturaMemberJune 26, 2015 at 6:26 pm #157629carrieoke13ParticipantRen , or anyone else, I am trying to add onto this and show the child pages of the child pages (and thumbnails of all). What would I add to this query to make that happen? or would it be a separate query?
Thanks!
Carrie -
AuthorPosts
- The topic ‘Displaying Child Pages on Parent Page (with thumbnails)’ is closed to new replies.