Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Marcus Forsberg in November 16, 2008, 06:20:36 VORMITTAG

Titel: [Tip] Simple Countdown in header
Beitrag von: Marcus Forsberg in November 16, 2008, 06:20:36 VORMITTAG
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:

Code (Find) Auswählen
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], '</span>



Code (Replace whit) Auswählen
// 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
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Costa in November 16, 2008, 08:42:03 VORMITTAG
LOL

pretty funny Nascar :)

Thank you for sharing with us.
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: genieuk in November 16, 2008, 10:39:25 VORMITTAG
Thank you  :D

Just what i wanted.

Regards,
Mathew
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Dr.Stinglock in November 18, 2008, 12:18:22 VORMITTAG
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$minute0$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";
}
?>


Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Marcus Forsberg in November 18, 2008, 12:51:16 VORMITTAG
Actually that's a better script, rodregis :P
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: glennk in Dezember 28, 2008, 03:31:36 NACHMITTAGS
is it possible to count up ? I need one to count time gone since a certain event ??
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Marcus Forsberg in Dezember 28, 2008, 03:34:25 NACHMITTAGS
This might work

Code (Find) Auswählen

   $difference =($target-$today) ;


Code (Replace whit) Auswählen

   $difference =($target+$today) ;
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: FlixyaFriend in Januar 19, 2009, 04:23:34 VORMITTAG
Thank Dear Sir,Nas  :P
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: enjoy1985 in Januar 25, 2009, 10:23:34 NACHMITTAGS
Pretty nice tip
thanks you. :D
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: TheListener in August 21, 2009, 02:14:53 NACHMITTAGS
Is there a demo of this working anywhere?

Nas this should be a mod.

Titel: Re: [Tip] Simple Countdown in header
Beitrag von: jani01 in August 23, 2009, 03:27:44 NACHMITTAGS
very nice tip.  Thanks from this end.

Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Costa in August 23, 2009, 04:20:28 NACHMITTAGS
Zitat von: TheListener in August 21, 2009, 02:14:53 NACHMITTAGS
Is there a demo of this working anywhere?

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi27.tinypic.com%2F2h3dki8.png&hash=9a14f81bf6120c00cc4ef20a91eb67522c77ffb7)
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: TheListener in August 23, 2009, 06:51:28 NACHMITTAGS
Thanks bud
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: qtime in November 18, 2009, 06:32:47 VORMITTAG
nice code!
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: raghhav in Dezember 01, 2009, 10:03:47 VORMITTAG
thanks for the good trick, can you tell me how to change the color and size of the font of output text
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: David12 in Dezember 30, 2009, 12:01:30 VORMITTAG
Nice Code..! Thank you so much for your nice trick. I really Thankful to you. Keeping us post.
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: BigErn in November 14, 2010, 09:27:18 NACHMITTAGS
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?
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: Masterd in November 25, 2010, 12:56:49 NACHMITTAGS
Zitat von: cσσкιє мσηѕтєя in November 16, 2008, 06:20:36 VORMITTAG
Code (Replace whit) Auswählen
// 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!";
Titel: Re: [Tip] Simple Countdown in header
Beitrag von: TheListener in Juni 16, 2011, 02:14:29 NACHMITTAGS
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.