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. Instead 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:
03 | while (have_posts()) : the_post(); ?> |
04 | $expirationtime = get_post_custom_values( 'expiration' ); |
05 | if ( is_array ( $expirationtime )) { |
06 | $expirestring = implode( $expirationtime ); |
09 | $secondsbetween = strtotime ( $expirestring )-time(); |
10 | if ( $secondsbetween > 0 ) { |
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.
No comments:
Post a Comment