[wp-hackers] Simple Idea for Expiring Posts
Dennis Williamson
dennis at netstrata.com
Wed Oct 13 23:40:50 UTC 2004
Some people have asked for a way to expire posts.
http://wordpress.org/support/10/10546
http://wordpress.org/support/4/11122 (refers to rss, my idea doesn't
address that unless indirectly)
Here is a solution that I came up with and I'd like comments, please:
In index.php, immediately after The Loop begins (just below the foreach), add:
<?php list ($post_expired) = get_post_custom_values('postexpire'); /* only
pay attention to the first one if there's a duplicate */ ?>
<?php if ( !$post_expired || current_time('mysql') < $post_expired) : /*
if there's no expiration date or it's not been reached yet, go ahead with
displaying the post */ ?>
Just before the endforeach, add:
<?php endif; /* end not-expired test */ ?>
For any post you'd like to expire, add a custom field with the key of
'postexpire' and the value of the date you'd like the post to expire in
"mysql" form (yyyy-mm-dd hh:mm:ss).
The post is still in the database and could be edited to un-expire it.
Existing posts can be retroactively expired.
You can future-date a post with the edit timestamp option and set it to
expire later. If you set the expire date earlier than the future-publish
date, the post won't appear.
I don't do any error checking on the value and I ignore any duplicates in
the post. Additional code could be added to do each of these.
It could be made into a plugin, but it's so short it just seems easier to
include directly in index.php.
Dennis
More information about the hackers
mailing list