Display Future Posts in Your WordPress Theme
Today I want to focus on a very interesting feature of WordPress - the timestamp of a post or how to set a post on schedule and - and what else can we do with future posts. Learn how to run your blog on autopilot.
Maybe this happened to you once
All of a sudden you have a lot of inspiration and ideas for posts on your blog. Your head is full with first class content
and you want to write 5 posts… one after another. But since we all know that publishing all these posts at once is a waste of energy, we decide to spread the new content across several days or even weeks.
Or maybe you go on vacation for four weeks (lucky you!) but you want to keep offering your ‘Friday Web Design Blog Review’.
Wouldn’t it be nice to run your blog on autopilot?
To set a post on schedule to be publihed on a certain date at a certain hour is quite easy. In the write post panel in the right sidebar you’ll see the ‘Publish Status’ box. Under ‘Keep this post private’ it says ‘Publish immediately’. Click on ‘Edit’ next to it.

A form opens up where you can change the timestamp of the post. Here you can set the exact date and hour when you want you post to be published. If you choose a future date your post will appear as scheduled in the manage posts overview.
Your blog runs on autopilot now!
What else can we do with this timestamp feature?
Now we know that we can save posts with a future date. But can we display them on our blog? Yes, we can. And because we can, I had the idea of building an Upcoming Events list like in the example below.

In my example we have a list with upcoming events and onther list below with previous events. Please note that the upcoming events list is in chronological (ascending) order. Once a future event date passes, it will automatically change to the Previous Events list.
First I want to show you how to call the previous events. Since these are normal posts, we just make a normal query for posts of a certain category - here events. If there are no previous events, the phrase No previous Events will be displayed.
<h4>Previous Events</h4>
<?php
$my_query = new WP_Query('category_name=events');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No previous Events'); ?></li>
</ul>
<?php endif; ?>Now we try to display the future posts just adding some arguments to the post query.
<h4>Upcoming Events</h4>
<?php
$my_query = new WP_Query('category_name=events&post_status=future&order=ASC');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No upcoming Events'); ?></li>
</ul>
<?php endif; ?>Please note that the WP_Query function now only asks for posts with post_status future and will display them in an ascending (chronological) order. If there are no upcoming events, the phrase No upcoming Events will be displayed.
Put it all together
In my example I want to display the upcoming events on the top and the previous events below. So here you get the complete code:
<h4>Upcoming Events</h4>
<?php
$my_query = new WP_Query('category_name=events&post_status=future&order=ASC');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No upcoming Events'); ?></li>
</ul>
<?php endif; ?>
<h4>Previous Events</h4>
<?php
$my_query = new WP_Query('category_name=events');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No previous Events'); ?></li>
</ul>
<?php endif; ?>Now just style the list to your liking and you have a nice automatic events list divided into upcoming and previous event.
Ähnliche Artikel
Hat Dir der Artikel gefallen?
11 Kommentare zu Display Future Posts in Your WordPress Theme
Sag Deine Meinung!
Free WordPress Themes
Beliebte Artikel
User Kommentare
Alex sagt zu Superfish jQuery Menu IE z-index Bug:
Nice one! I read the klog post before reading this and somehow I had missed...
webdemar sagt zu Frohes Neues!:
@Kristin:
Vielen Dank ;-)...
Kristin sagt zu Frohes Neues!:
Ich wünsche dir auch ein frohes neues Jahr. Ich wünche dir viel Glück bei d...
Alec sagt zu WordPress Theme deFusion 0.9:
Really like your deFusion theme. I've tinkered with it, and thought you mig...
Ahmet Topal sagt zu Sticky Posts in WordPress 2.7:
Ich glaube, dass war Otto42, der dass mit dem Query gesagt hat :?...
22. Dezember 2008
[...] Cette petite fonction est très pratique puisqu’elle vous permettra de donner un avant goût de vos prochains articles de votre blog. Un bon moyen pour fidéliser indirectement vos visiteurs en leur donnant les titres de vos prochains billets. Via Webdemar. [...]
21. Dezember 2008
Wow, never thought/knew of “post_status=future” to display future scheduled posts. This is a great tip!
20. Dezember 2008
[...] anunţ pe cititori despre titlurile acelor articole. Azi am găsit pe portalul http://www.webdemar.com o soluţie foarte bună pe care am şi aplicat-o. Am avut să studiez puţin şi să fac unele modificări la [...]
19. Dezember 2008
Thank you very much. I was looking for a long time after such an advice and I already use this on my romanian part of the blog and also, wrote an article in Romanian so that people may use it. Thank you very much and may God bless you with a blessed Christmas and with the gift of Eternal Life through faith in our Lord Jesus Christ.
29. November 2008
I love this idea. I am going to use your idea for my membership site (I created using wordpress).
3. November 2008
Hmm, looks mighty similar to the code posted here back in June …
http://www.keithmillington.co.uk/wordpress/?p=22
28. Oktober 2008
I don’t want to repeat what other have said but this is a great article. I would have to try this.
24. Oktober 2008
What a great tutorial - I’ve been looking for something like this for a year now - thanks!
20. Oktober 2008
Great tip! I was checking out your themes (which are gorgeous, by the way), when I found this post. Very timely. I put it to work right away on my own blogs, then I published a similar tip on my site, with a link back here, of course. I didn’t go into the depth that you did. I figured it people wanted to go that deep, they could learn that here. Nice job.
16. Oktober 2008
Great article. I could really use the information here. I had been looking for this sort of thing for a while. Thanks
11. Oktober 2008
Thanks dude! The events list is a great use of this Wordpress feature!