Set a simple countdown timer using custom fields
-
I’ve found a great little bit of PHP that will calculate and display how many days there are left until a certain date in the future.
<? $day = 11 ; // Day of the countdown $month = 3; // Month of the countdown $year = 2011; // Year of the countdown $hour = 23; // Hour of the day (east coast time) $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600); $hours = (int)$calculation; $days = (int)($hours/24); ?> <p> <?=$days?> days</span> left to go</p>Thank you, Joe Crawford http://lab.artlung.com/countdown/
My problem is I want to be able to specify the date that is being counted down to using Custom Fields specific to a particular post.
So I’ll have 3 custom field Names called “countdown-date”, “countdown-month” and “countdown-year” and get them to spit out the values in the PHP above.
So far my miserable PHP skills have come up with stuff like:
<? $day = <?php get_post_meta($post->ID, 'countdown-date', true); ?> ; // Day of the countdown $month = 3; // Month of the countdown $year = 2011; // Year of the countdown $hour = 23; // Hour of the day (east coast time) ...But these give me error messages. I hope someone would know how to do this.
This is within the loop.
The topic ‘Set a simple countdown timer using custom fields’ is closed to new replies.