Advertisement:

Author Topic: [Tip] Simple Countdown in header  (Read 38915 times)

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
[Tip] Simple Countdown in header
« on: November 16, 2008, 06:20:36 AM »
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) [Select]
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], '</span>


Code: (Replace whit) [Select]
// 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

Offline Costa

  • SMF Hero
  • ******
  • Posts: 3,045
  • Gender: Male
  • Do NOT feed the trolls...
Re: [Tip] Simple Countdown in header
« Reply #1 on: November 16, 2008, 08:42:03 AM »
LOL

pretty funny Nascar :)

Thank you for sharing with us.
Hugo "Costa" Fernandes
Todas as MP's a pedir ajuda são sujeitas a radioactividade, microondas, queimadas e atiradas borda fora.

"At least someone appreciates the fact that I am doing and not thinking..."
"Laziness is counter-revolutionary."

Offline genieuk

  • Sr. Member
  • ****
  • Posts: 779
  • Gender: Male
Re: [Tip] Simple Countdown in header
« Reply #2 on: November 16, 2008, 10:39:25 AM »
Thank you  :D

Just what i wanted.

Regards,
Mathew

Offline Dr.Stinglock

  • Semi-Newbie
  • *
  • Posts: 28
Re: [Tip] Simple Countdown in header
« Reply #3 on: November 18, 2008, 12:18:22 AM »
Would it be hard to make that work with a countdown script I found here ?

I was just wanting to countdown hours/minutes as well.


Code: [Select]
<?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";
}
?>

Those large signatures really look great!
Especially when it takes up ten times the size of the actual post!!

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
Re: [Tip] Simple Countdown in header
« Reply #4 on: November 18, 2008, 12:51:16 AM »
Actually that's a better script, rodregis :P

Offline glennk

  • Sr. Member
  • ****
  • Posts: 899
Re: [Tip] Simple Countdown in header
« Reply #5 on: December 28, 2008, 03:31:36 PM »
is it possible to count up ? I need one to count time gone since a certain event ??

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
Re: [Tip] Simple Countdown in header
« Reply #6 on: December 28, 2008, 03:34:25 PM »
This might work

Code: (Find) [Select]
   $difference =($target-$today) ;
Code: (Replace whit) [Select]
   $difference =($target+$today) ;

Offline FlixyaFriend

  • Semi-Newbie
  • *
  • Posts: 18
    • samsung ue46c8000
Re: [Tip] Simple Countdown in header
« Reply #7 on: January 19, 2009, 04:23:34 AM »
Thank Dear Sir,Nas  :P


TheListener

  • Guest
Re: [Tip] Simple Countdown in header
« Reply #9 on: August 21, 2009, 02:14:53 PM »
Is there a demo of this working anywhere?

Nas this should be a mod.


Offline jani01

  • Jr. Member
  • **
  • Posts: 100
    • Pakistan Biggest MP3 songs Portal
Re: [Tip] Simple Countdown in header
« Reply #10 on: August 23, 2009, 03:27:44 PM »
very nice tip.  Thanks from this end.


Offline Costa

  • SMF Hero
  • ******
  • Posts: 3,045
  • Gender: Male
  • Do NOT feed the trolls...
Re: [Tip] Simple Countdown in header
« Reply #11 on: August 23, 2009, 04:20:28 PM »
Is there a demo of this working anywhere?

Hugo "Costa" Fernandes
Todas as MP's a pedir ajuda são sujeitas a radioactividade, microondas, queimadas e atiradas borda fora.

"At least someone appreciates the fact that I am doing and not thinking..."
"Laziness is counter-revolutionary."

TheListener

  • Guest
Re: [Tip] Simple Countdown in header
« Reply #12 on: August 23, 2009, 06:51:28 PM »
Thanks bud

Offline qtime

  • Full Member
  • ***
  • Posts: 501
Re: [Tip] Simple Countdown in header
« Reply #13 on: November 18, 2009, 06:32:47 AM »
nice code!

Offline raghhav

  • Semi-Newbie
  • *
  • Posts: 31
  • Spidey Looked it
    • Send SMS
Re: [Tip] Simple Countdown in header
« Reply #14 on: December 01, 2009, 10:03:47 AM »
thanks for the good trick, can you tell me how to change the color and size of the font of output text

Offline David12

  • Newbie
  • *
  • Posts: 1
Re: [Tip] Simple Countdown in header
« Reply #15 on: December 30, 2009, 12:01:30 AM »
Nice Code..! Thank you so much for your nice trick. I really Thankful to you. Keeping us post.

Offline BigErn

  • Semi-Newbie
  • *
  • Posts: 65
Re: [Tip] Simple Countdown in header
« Reply #16 on: November 14, 2010, 09:27:18 PM »
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?

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,887
  • Gender: Male
  • Sapienti satis.
Re: [Tip] Simple Countdown in header
« Reply #17 on: November 25, 2010, 12:56:49 PM »
Code: (Replace whit) [Select]
// 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

Code: [Select]
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

Code: [Select]
$txt['christams_countdown'] = "Only $days days to christmas!";
« Last Edit: December 20, 2010, 02:55:50 AM by Masterd »
My Mods

Sugested that too. Hey ho. I'd link you to the original discussion but it's not visible to most people (seekrit team board stuff that is more dangerous than wikileaks).


Don't PM me for support! Use the appropriate support board!

TheListener

  • Guest
Re: [Tip] Simple Countdown in header
« Reply #18 on: June 16, 2011, 02:14:29 PM »
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.