Lookhappy Design

30 November 2016

Displaying WordPress childpages with thumbnails

Here’s a little bit of code to display WordPress Childpages in an undordered list including their thumbnail image.


<ul class="sub_pages">
				<?php
				$args = array(
				'post_parent' => $post->ID,
				'post_type' => 'page',
				'post_status' => 'publish'
				);
				$postslist = get_posts($args);
				foreach ($postslist as $post) :
				setup_postdata($post);
				?>
				 <li class="single_subpage">
				 	<a href="<?php the_permalink(); ?>">
				 	<?php if(has_post_thumbnail()) { ?>
		                <div class="featured_image">
							<?php the_post_thumbnail('thumbnail'); ?>
						</div>
					<?php } else { ?>
						<div class="placeholder_block"></div>
					<?php } ?>
					 <h2><?php the_title(); ?></h2>
					 <!-- <?php the_excerpt(); ?> -->
					 </a>
				 </li>

				<?php endforeach; ?>
				<div class="clear"></div>
			</ul>