Help - Search - Members - Calendar
Full Version: PHP conditional
Movable Type Community Forum > Additional Resources > Tips and Tricks
TDGoddard
If I don't get around to posting on my blog for XX hours, I'd like to have a block of HTML appear at the top of my blog. When I make a post, I'd like to have this disappear until XX hours after the post appears.

I'm sure this can be done with PHP and some MT date tags in the template. Can anyone give me a hint?

Thanks.
ndns
I'm going to point you in the direction of the PHP mktime(); function.

I don't have time to work on any scripts at the moment, but maybe someone else will.
kadyellebee
I like using strtotime.

Try something like this:
CODE
<MTEntries lastn="1">
<?
$entrytime = strtotime("<$MTEntryDate format="%x %X"$>");
$now = strtotime("now");
$diff = ($now-$entrytime)/(3600); //because you want hours
if ($diff > 24) {  
echo "It has been too long since my last post!!<br />";
}
?>
</MTEntries>


I always have to play with the time to make sure I'm dividing it by the correc thing.. $diff will give you the current time minus the last entry's time in seconds. And so since you want XX HOURS as the testing option, dividing it by 60 seconds * 60 minutes will give you the number of hours. Change 24 to be how many hours you want it to test (your XX value).

Let me know if this works for you; I only briefly tested it! smile.gif

Kristine
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.