Display your WordPress Recent Posts FAQs
In 2012 I published a tutorial display your WordPress Recent Posts on a Static Page. I wouldn’t ever have dreamed that it would be one of the most commented posts on my blog and even now people are still asking for hints and tips on how to expand the code further so I’ve decided to go through all the comments and gathered enough to have a FAQ section.

**Generally all code will be specified in the loop unless otherwise stated**
Featured Images (Post Thumbnails)
My featured Image doesn’t show up.
If your post thumbnails don’t work make sure you have set a featured image on your post edit screen and make sure you have included the following snippet in functions.php
1<?php add_theme_support( 'post-thumbnails' );?>
Can I change the size of my featured image?
If you want to use the default image size then simply use
1<?php the_post_thumbnail(); ?>
You can also change the size of your post’s featured image by choosing one of the following.
1the_post_thumbnail('thumbnail'); // 150x150
2the_post_thumbnail('medium'); // 300x300
3the_post_thumbnail('large'); // 1024x1024
4the_post_thumbnail('full'); // Original size
5the_post_thumbnail(( array(100, 100) )); // Custom size
If that doesn’t work then you can try the following code snippets instead.
1<?php echo get_the_post_thumbnail($post->ID, 'full'); ?>
2<?php echo get_the_post_thumbnail($post->ID, array(100,100),'thumbnail');?>
Errors
If you get PHP errors check that your path to wp-blog-header is correct and you have used a relative link
1folder/wp-blog-header.php
rather than an absolute link
1https://mydomain
Also check for any whitespace after the opening and closing PHP tags, particularly in your functions.php.
If you get 404 errors try adding the call to the blog header below the doctype If that doesn’t work then add the following under the call to blog header but above the doctype tag.
1<?php require('wp-blog-header.php');
2
3// if you are getting 404 errors add the next 2 lines
4status_header(200);
5nocache_headers();
6
7?>
8
9<!--HTML starts here-->
To enable error messages but not display them check/add your wp-config.php for/with the following
1<?php
2
3define('WP_DEBUG', true); // or false
4if (WP_DEBUG) {
5define('WP_DEBUG_LOG', true);
6define('WP_DEBUG_DISPLAY', false);
7@ini_set('display_errors',0);
8}
9?>
Pages & Posts
Can I get the full content or excerpt?
If you want to add the full content use
1the_content();
and if you only want to display a snippet use
1the_excerpt();
Can I display the full post content without the more tag?
Yes add the following above the loop
1<?php global $more; $more=1; ?>
and the following inside the loop
1<?php the_content(); ?>
Can I display pages instead of posts?
Yes simply change an argument in the $args array.
1<?php $args = array( 'numberposts' => 6,
2'post_status'=>"publish",
3'post_type'=>"page");//change post_type from post to page
4?>
Can I choose what posts or pages I want to display?
Yes but only by post or page ID
Can I choose what Categories I want to display?
Yes but only by Cat ID
Can I use a unordered list instead of a DIV?
Yes, sure you can just remember to add the opening
1<ul>
tag above the foreach loop and the closing tag
1</ul>
below the loop.
Can I use this code within my current WordPress theme?
Yes, but the code is slightly different depending on the outcome you want. If you want the posts outside the loop then the original code snippet should work.
If you are adding the posts inside a theme page that already contains the loop, my preference would be to add a new function inside functions.php and call it within that loop, as shown in the examples below.
The following goes inside functions.php
1<?php
2
3// Get the latest 10 posts function to add to functions.php
4
5function get_wow_posts(){
6
7global $post;
8$args = array(
9'numberposts' => 6,
10'post_status'=>"publish",
11'post_type'=>"post",
12'orderby'=>"post_date");
13
14$postslist = get_posts( $args );
15
16echo '<ul id="latest_posts">';
17
18foreach ($postslist as $post) : setup_postdata($post); ?>
19
20<li>
21 <strong><?php the_date(); ?></strong><br />
22
23 <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
24<?php the_title(); ?>
25 </a>
26
27</li>
28 <?php endforeach;?>
29</ul>
30 <?php wp_reset_postdata();
31}
32?>
Below is an example, highlighted on line 13, of displaying posts inside a typical theme page by calling the function.
1get_wow_posts();
above. Please note that all themes differ.
<?php the_title(); ?>
<?php endif; ?>Nothing has been posted like that yet
1<?php echo get_post_meta($post->ID, 'teaser', true); ?>
1<?php the_date();?>
1<?php echo get_the_date();?>
1<?php define('WP_USE_THEMES', false); ?>