Nov
10
2009
Display a List of Upcoming Posts in WordPress
When you have completed a post in WordPress, you have the ability to save it as a draft, publish it immediately or schedule a future date when it will be published automatically. This is extremely helpful if you want to plan ahead or if you use your WP site for events. Creating a simple list of upcoming posts lets your visitors know what they can look forward to and is pretty simple to do.
The following code can be placed in your sidebar on within any template.
<?php $futurePosts = new WP_Query(); $futurePosts->query('showposts=5&post_status=future&order=ASC'); if ($futurePosts->have_posts()) : while ($futurePosts->have_posts()) : ?> <ul> <li><?php the_title(); ?><br /><small><?php the_time(get_option('date_format')); ?></small></li> </ul> <?php endwhile; else: ?> <ul> <li>No upcoming events.</li> </ul> <?php endif; ?> |
If you want to only display future posts from a specific category, you can add a cat=$id to the query like so:
$futurePosts->query('showposts=5&post_status=future&order=ASC&cat=12'); |
Be sure to change the “12″ to the category ID.



I am unable to get your code to work on a new WP 2.8.6 installation. I have inserted your code, with the cat, into the page http://theindependentview.com/?page_id=25 and it causes the page to display no content beyond the page title. I have tried with bracketed code before and after the Php code, also I am using a plugin to execute Php code.
No errors are returned.
Nice code, but you missed a closing bracket:
how would i create different color backgrounds for each ?
This is exacly what we needed for our website’s content being created. Thank you very much for sharing this Bavota!
Just wanna say that this is invaluable , Thanks for taking your time to write this.
Now that is a real handy bit of code – I usually add 4 or 5 posts to my blog at a time, and schedule most of them for a few days in the future. Having this widget means my readers can see what’s coming up in the next few days and will be more likley to bookmark my site, subscribe to my feed and come back to visit in the future.
Genius!
Thanks for posting the html clode for that. This is going to be very helpful for the new site we are creating.
We appreciate you posting the code for that. This is definitely going to be great when we start our new website!
This is something I will definitely implement in the future. I don’t have much time to blog currently, but when I have a lot of blog posts ready to post, I’m going to install this.
Thanks,
Mike