Updated: Wordpress post expiration code


/ Published in: PHP
Save to your folder(s)

All you need to do when writing the post, is enter a custom field with the key "expiration" and set the value in the format: "2010/01/01 18:20:00" - this would expire the post at 6.20pm on the 1st January 2010.


Copy this code and paste it in your HTML
  1. ***PUT THIS INSIDE THE LOOP, FIRST THING***
  2.  
  3. <?php //to check against expiration date;
  4. $timestamp = strtotime("now + 8 hours");
  5. $currentdate = date('YmdHis', $timestamp);
  6. $expirationdate = get_post_custom_values('expiration');
  7. if (is_null($expirationdate)) {
  8. $expirestring = '30005050235959'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
  9. } else {
  10.  
  11. if (is_array($expirationdate)) {
  12. $expirestringarray = implode($expirationdate);
  13. }
  14. $markup = array("/",":"," ");
  15. $expirestring = str_replace($markup,"",$expirestringarray);
  16. } //else
  17. if (( $expirestring > $currentdate ) || (is_archive())) { ?>
  18.  
  19. ***THEN PUT THE FOLLOWING LINE AT THE VERY END OF THE LOOP***
  20.  
  21. <?php } //end if for expiration; ?>

URL: http://www.nrbet.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.