Over on Performancing.com Andy, says the money is in the archives, stupid. Nick talks about Monetizing your Blog, by showing different levels of advertising based on how old post is and whether someone is logged in or not. Now Andy’s doing a blog monetization makeover, and time sensitive ads came up again. Since I’ve got the hood open on this WordPress install I figured I would work up some code to figure out how old a post is.
$postdate = str_replace("-", " ",substr($post->post_date, 0,10));
$postd = explode(" ", $postdate);
$ageunix = (( time() - mktime('','','', $postd[1], $postd[2], $postd[0])));
$days_old = floor($ageunix/(24*60*60));
Basically what I’m doing is getting time and date of the post. I then isolate the just date and remove out “-” characters. I explode it into an array, convert them to unixtime, and do the subtraction. Then convert it back from UNIX time to days old expressed as an integer value (my high school math teacher Sister Miriam would be proud).
Related posts:
- Wordpress SEO: Wordpress Security Why it Matters to SEO In recent weeks wordpress security, or more correctly the lack...
- How to Use Evernote to Create the Ultimate Post Conference Reference Guide Now that Pubcon is over I’m going to let you...
- Wordpress SEO: How to Choose a Permalink Structure For this post we’re going to be taking look at...












{ 7 comments }
Spare yourself a few lines of code :
$ageunix = time() – get_the_time(’U');
$days_old = floor($ageunix/(24*60*60));
(on a side note, your captcha system is way too annoying… Had to try 3 times to get this comment posted. There are many WP plugins less intrusive and as effective)
I tried that wasn’t working on my dev server for some reason, but it works on the live one, go figure.
Well you can otherwise spare a line by not replacing the dashes with spaces. Just perform the explode on the dash.
Does wordpress not have an accountsystem? I have to add my name and email etc again everytime I post.
Does wordpress not have an accountsystem? I have to add my name and email etc again everytime I post.
Sure it has an accountant system, didn’t you get your password?
*hits head on desk*
I’m glad wordpress has sorted all this out now. It’s like you had to be a genius to work this out. Lucky for us now.
Wow. You gys must have been pioneers or something. Wordpress is so easy to use these days.
Comments on this entry are closed.