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.
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
Thanks for this snippet! I am often scheduling posts ahead and was thinking abotu doing exactly this.
Glad it helped! I love this recipe
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?
@Rarst: No it isn’t hard at all
Just add your title and <ul> element below the if ($my_query->have_posts()) line.
@jbj
Tried that, I get “unexpected <” error. Clueless in PHP, I keep wanting to read on it and never get to that.
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<?
Glad it works
This WILL come in useful. Thanks for the useful code
Great tip and a nice way to keep your blog visitors engaged and keep them curious about future posts.
Is there a way to include the future publication date along with the title?
@Brian McDaniel: I don’t know, I’m going to look for it
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)
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: