WordPress comes with a lot of cool features but ability to schedule your blog posts and publish them on specific time in future is one of my favorite. It is recommended that you don’t over load your readers by publishing all articles at once but schedule them to publish in uniform gap. This way you can write as much as you want and queue up all your posts for the future. While scheduling posts for future, you might also want to show you readers, what to expect in a certain amount of hours. You can create a small section to display upcoming posts or articles on your WordPress website. In this tutorial, we will show you how to display upcoming posts in WordPress.
Although there are some WordPress plugins available in WordPress plugin repository to display upcoming posts, which you can use if you don’t want to get your hands dirty with PHP code. But why use a plugin to create a simple feature when you can develop it with a couple of lines of code in your theme files, especially when it can easily be written.
Just paste this code in your theme files where you want to display upcoming posts list, preferably in sidebar but you are not restricted by it. It’s important to note that this code should not go in functions.php file.
<h3>Upcoming Articlesg</h3> <ul> <?php // display upcoming posts in wordpress without a plugin $args = array( 'post_type' => 'post', 'post_status' => 'future', 'order' => 'DESC', 'ignore_sticky_posts' => 1, 'posts_per_page' => 5, ); $upcoming_post_query = new WP_Query( $args ); if ( $upcoming_post_query->have_posts() ) : while ( $upcoming_post_query->have_posts() ) : $upcoming_post_query->the_post(); ?> <li><?php the_title(); ?></li> <?php endwhile; endif; wp_reset_postdata(); ?> </ul>