Version 2.0.0: Peter’s Date Countdown Plugin for WordPress
First published on February 3, 2007
After I posted about php code for countdowns, a couple of people asked me to implement it into their WordPress installation. However, for ease of management of countdown items, I decided to simply make a WordPress plugin for it. I’ve seen a few similar plugins already available, but none of them seem to have a user-friendly management page.
Here’s a screenshot of the management page in the WordPress admin section:
Here’s a screenshot of the output in a sidebar:
To install the plugin:
Unzip all files to a “peters-date-countdown” subdirectory in your WordPress plugin directory. The download link is below.
Activate it in the Plugins menu of your admin section. There are a few settings at the top of the plugin file to tweak several features (for example, you can enable the new JavaScript real-time countdown feature), so you should edit that as well.
Then, paste this code wherever you wish to display the countdowns:
<?php countdown_callit(); ?>
Starting from version 1.6 onwards, if you want to call a specific countdown, enter the number of the countdown item that you want to display in parentheses, such as this:
<?php countdown_callit(3); ?>
If you want to put the countdowns on your sidebar, here’s the code for most themes (paste this in sidebar.php):
<li> <h2>Countdowns</h2> <?php countdown_callit(); ?> </li>
Alternatively, you can use the plugin as a WordPress widget (see the “Design… Widgets” page).
You can then add, delete, and update countdown items on the “Manage… Date Countdown” page of your admin section.
If you are upgrading, make sure that you do NOT overwrite datecountdowndates.php! Also, make sure that the files are placed in the folder “wp-content/plugins/peters-date-countdown”
Peter’s Date Countdown Plugin for WordPress Version 2.0.0 -August 25, 2008: Finally combined the widget and non-widget versions of this plugin into one version.
Download site 1 | Download site 2
—————————-
Countdowns in use:
New support forum, which is better for organizing questions and comments:
Forum/Topic | Started | Last post | Posts |
---|
August 10th, 2006 at 2:28 pm
Leah says:
I love it! Go visit my website and see my countdowns!
August 10th, 2006 at 10:36 pm
Julia says:
I love it too!
Great skill Peter!
August 12th, 2006 at 9:57 am
nate says:
im getting errors with your script. when i try to add a date to the count down… if you could email me, i’ll reply back with the errors im getting. i’d greatly apprieciate it.
August 12th, 2006 at 12:47 pm
Peter says:
Update: I got in contact with Nate. Seems to be a permissions error. Not only does the datecountdowndates.php file need to be writable, but your user / group needs to have write permission.
If you’re getting errors similar to below, ask your server admin to check the permissions on the users / groups:
Warning: fopen(../path/to/blah): failed to open stream: Permission denied in path/to/blah on line X
Warning: fwrite(): supplied argument is not a valid stream resource in /path/to/blah on line X
August 16th, 2006 at 9:36 am
cricket says:
Great plugin!
I have a stupid question, though. (sorry!)
“Not only does the datecountdowndates.php file need to be writable, but your user / group needs to have write permission.”
Um…forever? In other words, do I just leave those permissions turned on indefinitely?
Thanks muchly
August 16th, 2006 at 11:07 pm
Peter says:
A stupid question it is not! Yes — that file always needs to be writable because the script will always be interacting with it to update the countdown items.
August 28th, 2006 at 11:54 pm
nat says:
Hey, heres a request. could you make it so that the sooner it gets it turns into counting down hours, and then minutes?
August 29th, 2006 at 10:29 am
Peter says:
Good idea, Nat. This would be a slightly more involved tweak… I’ll see what I can do when I have the time!
August 29th, 2006 at 2:05 pm
Jim says:
Then, paste this code wherever you wish to display the countdowns:
How do I get the above code into a post when I use the html editor it always changes the above code. Or is it not possible to run from insde a post?
August 30th, 2006 at 12:13 am
Peter says:
To use PHP code inside a post, you’ll have to install a plugin similar to this one:
http://priyadi.net/archives/2005/03/02/wordpress-php-exec-plugin/
By default, WordPress doesn’t allow any PHP code inside posts…
October 18th, 2006 at 10:20 pm
Old Cat says:
Hi, I have added in some functionalities to this plugin… If you are interested to include them in the next release, please contact
In admin panel, the user can input a time till which the ‘finished’ text will be displayed. And when a visitor points cursor over the item in the countdown list, a tip will show up displaying the time of the event. Just some tiny little codes
I am using widgets now, so I made it into a widget too.
January 4th, 2007 at 11:45 am
Richard Bui says:
How do you customize it to say something else besides sleeps? Great plugin, BTW! Thanks!
January 28th, 2007 at 11:16 pm
Vishwas says:
I don’t know if this is the right place for a feature request, but your plugin works great. I’d like to see a count-up feature in some future versions. Just an Idea though.
Currently I’m using
a script (coded by someone else) to have a count-up function. for. e.g. : XX days since “some event occured” + your widget for countdown XX days before “some event happens”
It’d be really nice if you could add this count-up feature in the next version of your plugin. I
February 14th, 2007 at 6:05 am
tkearsey says:
hello,
great plugin. just a quick question. how do i allow my “editors” have access to the manage option to create countdowns? right now it’s only available to my admin account. thanks.
February 14th, 2007 at 7:18 am
tkearsey says:
Thanks for your help Peter! I’ll post your reply here for others:
You’ll have to edit the plugin and scroll down to this piece of code:
function datecountdown_adminmenu(){
add_management_page(‘Date Countdown’, ‘Date Countdown’, 9, ‘datecountdown.php’, ‘countdown_manage’);
}
That 9 refers to administrator accounts. Setting it to ‘7’ should give your editors access.
Worked for me perfectly.
February 28th, 2007 at 9:27 am
John Boyd says:
Great plugin, works like a charm. Thanks for keeping it updated!
March 25th, 2007 at 6:48 am
Stoffel says:
I’m using your plugin for quite a while, and discovered today that there’s a realtime java version. Cool! I just installed it, and played with it for a while. Everything works great, except there’s one glitch that I don’t like. When using the Java version, it starts counting negative numbers after an event has passed. I’m not very technical, so I don’t know if there’s an easy/quick/dirty way to make the java version act like the ‘normal’ version so that a text line is shown after an event has passed? Thanks for the plugin!
March 25th, 2007 at 6:46 pm
Dave says:
Peter – version 1.9 worked like a charm, and the countdown timer is working properly on all my pages. Thanks for being so responsive!
July 15th, 2007 at 2:36 am
cyberlussi says:
Very nice and smooth … I’d like to see a revision within you can easily change language by setting only a bunch of variables. That would be even greater!
July 20th, 2007 at 12:27 pm
Avi says:
Is it possible to change the date format to EST instead of GMT?
July 20th, 2007 at 2:50 pm
Peter says:
Yes — there is a setting at the top of the plugin file to set the time zone:
// Change this if you want to add or subtract hours from your server time
$timediff = 0;
July 23rd, 2007 at 5:34 pm
Tati says:
How I can change of number of events to apear in my sidebar?
July 23rd, 2007 at 7:02 pm
Peter says:
// Change this to equal the maximum number of countdowns to display at once. For an unlimited number of countdowns, make it equal 0
$numcountdowns = 0;
August 14th, 2007 at 9:35 pm
Thomas Durka says:
Hello,
how can i set the target for the links as “_blank” instead of “_self”?
With regards.
August 14th, 2007 at 10:20 pm
Peter says:
This will take some tweaking of the plugin file in three places:
Here (this piece of code appears twice):
// show link if there is one
if ($link <> "") {
print "<a href=\"$link\">";
}
Change the print line to:
print "<a href=\"$link\" target=\"_blank\">";
Here:
// display link if desired
if ($link <> "") {
print "href=\"$link\" ";
}
Change the print line to:
print "href=\"$link\" target=\"_blank\" ";
September 21st, 2007 at 9:34 am
Rex says:
got this:
Warning: fopen(../wp-content/plugins/datecountdown/datecountdowndates.php) [function.fopen]: failed to open stream: Permission denied in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 224
Warning: fwrite(): supplied argument is not a valid stream resource in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 225
Warning: fclose(): supplied argument is not a valid stream resource in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 226
September 21st, 2007 at 9:35 am
Peter says:
Did you make sure that datecountdowndates.php is writable (777 permissions)?
January 18th, 2008 at 2:54 am
ed says:
Hi Peter! just wondering if you can help me? I need the coundown for the number of users registered on my website. How do I change the code to look at the wordpress code for the number of registered users? instead of the time?
Thank you.
Ed
January 18th, 2008 at 9:34 am
Peter says:
Hi ed,
I don’t think what you’re suggesting is really a countdown, but rather a simple display of the user count?
You can show the number of users by putting this code somewhere in your template (maybe the sidebar or footer):
<?php print $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->users); ?>
For more detailed statistics, check out this plugin or this plugin .
April 10th, 2008 at 8:07 am
Leon says:
Hi Peter – your script looks very good.
Is it possible to link a count down event to a post? Ie – ‘ X more sleep to the Olympics’ and when clicked will take you to Olympics post.
Cheers – Leon.
April 10th, 2008 at 9:35 am
Peter says:
Yes, there is a field for a link when you go to Manage > Date Countdown.
August 20th, 2008 at 5:48 am
no says:
Could you please put widget capabilities into the normal plugin? WordPress wants me to upgrade 1.93w to plain old 1.93.
August 25th, 2008 at 4:56 pm
Peter says:
Yup, I’ve finally merged that into one plugin with version 2.0.0.
September 9th, 2008 at 9:51 am
Vzx says:
Hi Peter
Nice work on merging the plugin and widget into a single file. I’ve just got one more issue – every time I upgrade, the date countdowns and options are reset.
I believe this is because all the information is saved in the php files which get overwritten with every upgrade. Is there a way by which user created info is saved on the DB? this would preserve all the dates and option in b/w upgrades.
September 10th, 2008 at 10:43 pm
Peter says:
Hi Vzx, thanks for the suggestion. I originally put the countdown items in a file because I didn’t want to add even more database calls every time a page is loaded. When I get around to it, I’ll look into perhaps storing the countdown items (and options) in a database but making a cache file from the database.
In the meantime, just make sure to copy what’s in datecountdowndates.php!
September 15th, 2008 at 2:41 pm
Callow says:
Hi
really like your widget. It’s nice with the sleeps.
On my website I don’t want it with a caption, are there any options to delete this out of the sourcetext?
September 15th, 2008 at 3:17 pm
Peter says:
Hi Callow, yes you can remove the caption by removing the code that displays the "title" tag.
Replace this:
print "title=\"$dc_datedisplay (GMT $dc_gmtdiff)\">";
With this:
print ">";
October 30th, 2008 at 8:17 am
Ed B. says:
Hey Pete! Thanks for the countdown timer. Been looking for a simple one for a while.
I have an idea in the event you plan on continued development.
An auto delete function. For each event for example. Delete this event after xx days of completion?
What can I say? I’m lazy!! Thanks again for the time you put in to this widget.
November 8th, 2008 at 11:58 am
RC says:
Is there a way to set it up so that the countdown prefaces it with a date. For example. there’s a countdown widget out there that displays like this:
Nov 1 – Event Name (123 Days)
Ideally I’d like to see it where the widget says:
Nov 1: 23 more sleeps until Event Name
Just curious… awesome plugin,
RC
November 9th, 2008 at 5:42 pm
Peter says:
Hi RC, at the moment I have no short term plans for new versions of this plugin. However, all of the display logic is handled in the "countdown_execute" function in the plugin file, which you can certainly modify to your liking.
July 16th, 2009 at 11:07 pm
derhenry says:
Hey, good job!
It works fine. But: The number of sleeps isn’t correct, if you’re living in germany. Like I do. What can I do? :o)
Reply from Peter: Did you set the time zone in the plugin file to be relative to your server time? Also, if you want true “sleep” counting, like midnight-to-midnight, see this post.
August 6th, 2009 at 12:01 pm
jeff says:
I have this as a widget but the days are displaying wrong I don’t this its 78 more days to Sept 25th
Reply from Peter: The plugin calculates the number of days relative to the server time, so your server time might be a bit off. However, I see from your site that the count is displaying correctly now
December 6th, 2009 at 2:11 pm
Pavel says:
Hey Piter, grat job!
Best countdown plugin around!!
Quick question:
I’m using <?php countdown_callit(); ?> method to display your countdown and I was wondering if i can also "print" the variable of the date of the countdown (i only have one) close to the callit function.
Is there a variable to print? Something like <?php print $date_variable; ?>
Thank for the adnvice and compliments for the great job.
Pavel
Reply from Peter: There is no global variable for that, but you could include the datecountdowndates.php file and then access $importantdate[0][1] for the month; [0][2] for the day, [0][3] for the year; [0][5] for the hour; and [0][6] for the minute.
July 8th, 2010 at 1:51 am
Roger says:
Hi, is there any way to customize the look (font, style, color etc.) of the widget?
Reply from Peter: Yes, if you edit line 512 of the plugin to add a class to the list container, you can then style it as needed via CSS.
Example for line 512:
echo $before_title . $pdc_widget_header . $after_title . ‘<ul class="date-countdown">';