‘this post is oooooold’

published on April 25, 2009 » filed under Web 2.0, WordPress

i wanted to delete a plethora of posts on Meta Comment. mainly irrelevant and mostly useless i was close to just deleting everything pre-2009. fresh start. but i don’t like editing old posts, i hardly moderate comments- its a fun old world and reading some of my earlier stuff is always amusing (to me– and let’s get something straight it’s all about me).

the alternative plan was to separate the new posts from the (very) old… just this week i discovered a great hack for Wordpress that allows me to display a ‘this post is old’ banner on posts of a certain maturity. y’see when i switched over from iBlog there were a lot of formatting issues – not to mention missing images, broken links etc – i tried to weed them out over time, but got busy, so anything from ‘05/’06 is a real mess. yay for $date_check_age

this simple code checks the age of a post (set at 999 days or older here) then displays the ‘.expired’ element (must be defined in your CSS) only to visitors to those elderly posts… it doesn’t print (or echo?) the element in your new material. so:


< ?php
$date_check_age = '';
if (is_single()) {
$days = 999;
if (time() - strtotime($posts[0]->post_date_gmt) > ($days * 86400)) {
$date_check_age = 'this is an archived post' ;

}
}
?>

< ?php echo $date_check_age; ?>

i hope you find that useful, took me 4 years just to work it out. place the code (above) in your post theme below the actual post-content, you’ll need the CSS to go with it…

.expired {
background: #ca0000;
border-top: 5px solid #333333;
border-bottom: 5px solid #333333;
color: #eee;
text-align: center;
font-weight: bold;
font-size: 1em;
width: 100%;
margin-top: 40px;
padding: 10px 0 10px 0;
}

tweak it to hell, and have fun. thanks to the wordpress forums for this one . in other news- Starred Review 2.2 now available. woo!

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

© Callum Alden
design by callum