WordPress

WordPress: Publish Future Posts as Upcoming Events

We built a WordPress micro-site for Corporate Blogging for Dummies and wanted to have a section where we displayed upcoming events in the lower sidebar. The solution to do this is actually quite simple and built directly into WordPress. Within your theme, you can add a loop that only queries and displays future posts for a specific category that is only used for Future Events:

<?php query_posts('order=ASC&cat=3&post_status=future,publish');
if(have_posts()) :
while(have_posts()) : the_post();
if(strtotime(get_the_time("F jS Y")) > time()) :
continue;
else: echo $post->id; ?>
<li><p class="right">
<small>
<?php echo get_post_meta(get_the_ID(), 'location', true); ?>
</small>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
</p>
<p class="left"><strong>
<?php the_time("M"); ?></strong>
<?php the_time("d"); ?>
</p>
<div class="clear">
</div>
</li>
<?php endif;
endwhile;
else:
echo "Check back soon!";
endif; ?>

The query_posts method is placed just before the WordPress loop to limit the posts published to the query used. Since these are future scheduled blog posts (on the event date), you don’t have to worry about them being displayed on your core blog in your template. You may want to hide the categories from your category list, though. This can be accomplished by editing your category list in your WordPress template using the exclude option:

<ul><?php wp_list_categories('orderby=name&exclude=3'); ?></ul>

We also added metadata for the post to display a location for the event. This is accomplished using WordPress’ Custom Fields section. Simply type in location for the field name and your location for the value… then retrieve the location for display using the get_post_meta command above.

The resulting site is pretty cool, with a very unique design and layout that has all the elements necessary to promote the book:
Corporate Blogging Tips.png

3 Comments

  1. 1

    We also built a custom feed with the future events posted and modified the XML sitemap generation to publish future posts. If you’re using Arne Brachenwald’s XML Sitemap Generator, line 1747 of sitemap-core.php can be updated to <code>$where.=” (post_status IN (‘publish’,’future’) AND (post_type = ‘post’ OR post_type = ”)) “;</code>

  2. 2

Leave a Reply