Hello!
What a beautiful day! A perfect day of making some PHP coding.
Let's place a countdown in our forum header! :)
We'll start by finding ./Themes/default/index.template.php/.
If you do not use the SMF default theme, simply find the index.tempate.php of your current theme instead.
Then, we'll do one (Yes, only one) code edit in there:
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], '</span>
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], ' ';
$target = mktime(0, 0, 0, 12, 24, 2008) ;
$today = time () ;
$difference =($target-$today) ;
$days =(int) ($difference/86400) ;
print "(Only $days days to christmas!)";
echo'</span>';
Note that if you use a custom theme, the code may look different. If you're not sure what to do, ask me.
When we have a look at that code, we See "0, 0, 0, 12, 24, 2008".
Now, what in the world is that?
Well, it's simply the date we're counting to.
12 is the month, 24 is the date and 2008 is the year.
I choosed to countdown the days to Christmas, change to what ever date you like. :)
We also see " print "(Only $days days to Christmas!)";".
That's the message to display. $days are the number of days that are left, and basically what we're all here for.
And we're done.
Enjoy
Nascar
LOL
pretty funny Nascar :)
Thank you for sharing with us.
Thank you :D
Just what i wanted.
Regards,
Mathew
Would it be hard to make that work with a countdown script I found here (http://elouai.com/countdown-clock.php) ?
I was just wanting to countdown hours/minutes as well.
<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown(2010,1,1,0,0);
//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
echo "Today's date ".date("F j, Y, g:i a")."<br/>";
echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>
Actually that's a better script, rodregis :P
is it possible to count up ? I need one to count time gone since a certain event ??
This might work
$difference =($target-$today) ;
$difference =($target+$today) ;
Thank Dear Sir,Nas :P
Pretty nice tip
thanks you. :D
Is there a demo of this working anywhere?
Nas this should be a mod.
very nice tip. Thanks from this end.
Quote from: TheListener on August 21, 2009, 02:14:53 PM
Is there a demo of this working anywhere?
(http://i27.tinypic.com/2h3dki8.png)
Thanks bud
nice code!
thanks for the good trick, can you tell me how to change the color and size of the font of output text
Nice Code..! Thank you so much for your nice trick. I really Thankful to you. Keeping us post.
I'm trying to add a countdown timer to my header, but my code does not currently have the current time in it.
Would anyone be able to offer help on how to add this?
Quote from: cσσкιє мσηѕтєя on November 16, 2008, 06:20:36 AM
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], ' ';
$target = mktime(0, 0, 0, 12, 24, 2008) ;
$today = time () ;
$difference =($target-$today) ;
$days =(int) ($difference/86400) ;
print "(Only $days days to christmas!)";
echo'</span>';
Isn't this hardcoded?
Also, echo is faster than print.
Index.template.php echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], ' ';
$target = mktime(0, 0, 0, 12, 24, 2010) ;
$today = time () ;
$difference =($target-$today) ;
$days =(int) ($difference/86400) ;
echo $txt['christams_countdown'];
modifications.language.php$txt['christams_countdown'] = "Only $days days to christmas!";
I know this topic is rather old (as am I) but it is worth the risk.
I am looking for a countdown timer where the seconds are actually moving (like the clock on MKAware).
I would also require the font size to be changeable.
The reason for this is due to a new radio station being launched in the local area.