The posts, unless you change the normal sort, will be displayed with the newest post first and the oldest post last, so you don’t need to change the sort–just need to handle the posts differently. Didn’t test this but you could use something like this in your loop:
<?php
$onehour= 1 * 86400; //days * seconds per day
$twohours= 2 * 86400; //days * seconds per day
$post_age = date('U') - get_post_time('U');
if ($post_age <= $onehour) {
echo 'this post is an hour or less old ';
the_content();
} elseif ($post_age > $one_hour && $post_age<=$twohours) {
echo 'this post is over one hour old but less than two hours old';
the_content();
} elseif ($post_age > $twohours) {
echo 'this post if over two hours old';
the_content();
}
?>
Thread Starter
z0ro
(@z0ro)
thank you!..that helped 🙂
Yes but this should be:
$onehour= 1 * 3600; //hours * seconds per hour
$twohours= 2 * 3600; //hours * seconds per hour
I’m looking to show a BUY button on my site only on the most recent post (and the homepage, because that will be the most recent post anyways. I’m only showing one post at a time).
For posts that have been expired for 24 hours, the buy button needs to be hidden.
I think this is possible with the above, but I can’t get it to work.
could someone please help? Thank you so much!! I’m desperate since I have to launch this very soon! Thanks.