How to: List scheduled posts

Here’s a good idea to make your readers visit your blog more often, or suscribe to your rss feed: What about listing the title of your scheduled posts? If you’re interested to do so, just read this recipe.

Achieving this recipe is very easy: Just paste the following code anywhere on your template where you want your scheduled posts to be listed. You can change the max number or displayed posts by changing the value of showposts in the query.

<?php
$my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($my_query->have_posts()) {
    while ($my_query->have_posts()) : $my_query->the_post();
        $do_not_duplicate = $post->ID; ?>
        <li><?php the_title(); ?></li>
    <?php endwhile;
}
?>

Credits goes to Pascal Birchler for this awesome recipe!

26 Responses

Nov 11 2008 21:25

Thanks for this snippet! I am often scheduling posts ahead and was thinking abotu doing exactly this. :)

Nov 11 2008 21:45

Glad it helped! I love this recipe :)

Nov 11 2008 21:53

Hm, I thought about it a bit and need some follow-up. This will only output li-s, right? So if I make heading and have no scheduled posts I’ll end up with lonely heading and empty ul?

Is it hard to make it output whole block (with heading and ul) and make it output nothing if there are no scheduled posts at moment?

Nov 11 2008 23:36

@Rarst: No it isn’t hard at all :)
Just add your title and <ul> element below the if ($my_query->have_posts()) line.

Nov 11 2008 23:44

@jbj

Tried that, I get “unexpected <” error. Clueless in PHP, I keep wanting to read on it and never get to that. :)

Nov 12 2008 00:03

Never mind, solved. Had to add question mark tags to exclude text output from php code. Not sure it’s right but works. :)

?>Upcoming posts<?

Nov 12 2008 00:15

Glad it works :)

This WILL come in useful. Thanks for the useful code :)

Dec 25 2008 10:53

Great tip and a nice way to keep your blog visitors engaged and keep them curious about future posts.

Feb 08 2009 06:46

Is there a way to include the future publication date along with the title?

Feb 08 2009 09:06

@Brian McDaniel: I don’t know, I’m going to look for it :)

Feb 15 2009 16:05

Hello, great Hack.
is it possible to have the list in opposit order ?(the post in the top of the list will be the first to be published)

Feb 15 2009 16:21

I find by myself :
replace DESC by ASC (in ‘post_status=future&order=DESC&showposts=5′)

I’m such a looser in PHP, I cant’ believe it. Champagne!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required