This hack comes becomes very useful when you are running a contest because you might
be posting information such as clues or hints that you don’t want to stay up for ever.
of manually removing the article, you can just make it expire automatically. It also works
if you have a product that you are offering a discount on. You posted it on your blog,
but you don’t want that discount to stay on your blog after its over. So you can remove it
automatically with this code.
All you need to do is replace your WordPress Loop with this code:
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
$expirationtime = get_post_custom_values('expiration');
if (is_array($expirationtime)) {
$expirestring = implode($expirationtime);
}
$secondsbetween = strtotime($expirestring)-time();
if ( $secondsbetween > 0 ) {
// For example…
the_title();
the_excerpt();
}
endwhile;
endif;
?>
Once you have done that, you can use custom fields when writing a post to set an expiration date. Make sure you select the key “expiration” and use the the following date format: mm/dd/yyyy 00:00:00
Now this hack does not remove or unpublish the article instead it just excludes the article from being displayed in the loop
0 Response to "How set an Expiration Date for Your Posts?"
Post a Comment