Wordpress Plugin: Simple Countdown
June 18th, 2006
Prompted by the countdown on the teaser website for the new Transformers movie I decided to develop a super simple countdown plugin for Wordpress.
This plugin, aptly dubbed Simple Countdown, lets you pick a title for the event or time you’re counting down to and merely displays the title along with the remaining days, hours and minutes until the event occurs. The great thing about Simple Countdown is that you can use a plain english date and time, e.g., “next tuesday” or “july 23, 2006 noon”.
The details
Usage
Call the plugin with the following code (be sure to remove any extra spaces after the opening “less than” symbol and before the closing “greater than” symbol – WP keeps adding extra spaces when I post/edit this article).
From the sidebar or template file: < ?php cc_countdown('EVENT DATE AND TIME', 'EVENT TITLE', AUTO DELETE); ?>
From within a post: <!--cc_countdown:EVENT DATE AND TIME, EVENT TITLE-->
The title of the event and time remaining until it occurs will both be written to the page wherever the plugin is called.
Parameters
- EVENT DATE AND TIME
- (string) the date and time of your event can be written many ways, plain text, like the example above, or using digits, e.i., 09/13/2007. When calling the plugin from a post, placing a “-” (dash or minus sign) in front of the EVENT DATE AND TIME will remove the countdown after the date/time has passed.
- EVENT TITLE
- (string) Just write the title of whatever event is happening in plain text. This will be displayed as an
h5element on your page/template so make sure you’ve got a nice style for it. When calling the plugin from a post, this is an optional parameter and if added to the tag it can display the title of the event before the countdown. The title will be replaced with an “I’m sorry” message when the event time has passed. - AUTO DELETE
- (boolean) Determines whether the countdown should be displayed after the event has occurred. If AUTO DELETE is set to
FALSEwhen the event has passed “(Your event title) has already happened” will display wherever the plugin is called. Default isTRUE.
Version history
Version 1.0.1 — October 27, 2006
- Changed the output of the countdown for RSS readers to ask visitors to view the actual website to see the countdown. Without this message the post would constantly be marked as new because of the changing timer.
Version 1.0 — October 25, 2006
- Added ability to call the plugin from inside posts
- Modified some of the internal code structure
- Renamed the plugin, must now be called via
cc_countdowninstead ofms_countdown
Version 0.4 — July 8, 2006
- Added the ability to display years if the event is that far away
- Better grammar formation
- Changed the date difference calculations to use less code
- Removed a bunch of useless comments and unused code
Version 0.2 — June 18, 2006
- Released to the public
Installation instructions
To install Simple Countdown, download the latest version from the top of this page and expand the .zip file. Upload the ms_countdown.php file to your /wp-content/plugins/ directory.
When the file is finished uploading, log into your WP admin page and click on the activate link in line with the Simple Countdown plugin. The plugin is now installed and active.
To show the countdown to whatever event you’re counting down to, open up the theme page, such as sidebar.php or single.php, etc. — found in the wp-contents/theme/ folder — in a text editor like TextMate, Dreamweaver or even NotePad.
Once you’ve located the spot you’d like the countdown to show on that particular page, simple use the usage instructions at the top of this page to display the countdown. Save the file and upload it to your theme directory.
Questions, comments, suggestions
I always welcome questions, comments and suggestions on the WP plugins I release. If there is something you think I should add, let me know. Having trouble with the plugin as it is? I’m here for you. Just want to say thanks? Write about it on your blog.
This entry is filed under Web Development.
You can follow any responses to this entry through its feed.
On July 1st, 2006, Darren Smith said:
I’ve uploaded and activated the plugin but you don’t say where to put the code or where the settings appear? there is nothing in the the options for this plugin so I presume the details are filled in when you submit a page or post?
Bit more info would be good, thanks.
On July 1st, 2006, Mike said:
The code goes on whatever page or post you want the count down to be shown. For example, if you’re writing about when your next trip will be, you would put the code at the top of this post into the post you’re writing.
One thing to keep in mind, if you’re calling (aka, putting the code) this plugin from a post/page via the WP admin, you’ll need to have a plugin that will parse PHP in your posts/pages — WP doesn’t parse PHP code in posts or pages natively.
If, on the other hand, you want to put the count down in the sidebar or have it show in a certain spot on all or any pages, you can edit your template files either in a text editor or via the WP admin.
On July 23rd, 2006, Jauhari said:
Simple and cute…
Can I add the Text from other dinamycs source? like from event plugins? or from post?
Thanks
On July 24th, 2006, Mike said:
Depending on the source it is entirely possible to make the event title text dynamic.
Unfortunately, unless the plugin is hard-coded into the
post loopit won’t work — at least for the time being, unless you have a plugin that will allow your WP posts to understand PHP (as mentioned above).On August 1st, 2006, michele said:
well - neat thing - it just simply does not work - no matter what I do.
Followed the instructions precisely.
Insert the call code in the sidebar = does not work = get plain text showing on my page
same thing, on a regular page, same thing when plaing it in to the large header.
I copied and pasted your call code from your page here, have the plugin activated - yet get plain text. have Title and Date filled in - so it should show.
am using the latest WP [downloaded today and installed], I thought the plug would work with WP 2.x versions - but maybe not.
would welcome correcting feedback.
thanks,
michele
On August 2nd, 2006, Mike said:
Michele, what plain text is showing on the page? One thing to check, if you’re copying and pasting from this page, is that there are no extra spaces after the opening “less than” symbol ro before the closing “greater than” symbol — for some reason WP keeps adding an extra space when I post/edit this article.
On August 3rd, 2006, John said:
I tried to use this but its not showing up on my site. I saw in ms_countdown.php it says “Only show countdown if a title and date are set.” The title and date are suppossed to be edited on the ms-coundown.php page correct?….not on the call in the sidebar…..correct?
Do you have a link where we can see an example of this plugin?
On August 3rd, 2006, Mike said:
John, the title and date are to be set in the sidebar where you call ms_countdown. For example, in sidebar.php you would call the function like so:
ms_countdown('YOUR_TITLE', '12 june 2006')Obviously replacing
YOUR_TITLEwith the title you’d like to use and12 june 2006with the date your counting down to.One example of the plugin would be at the top of the sidebar on this site.
On August 3rd, 2006, John said:
Thanks that did it.
On September 28th, 2006, Mary Robinette Kowal said:
I tried using this, but it showed the wrong time. At 1:23 am on September 29th, I told it that I wanted an ending time of 23:59 on September 29th. The date returned said, “Tomorrow in 4 hours and 36 minutes” I tried changing it to 11:59pm, but it returned the same result.
On January 30th, 2007, Dave said:
I’m curious what relationship this plugin has with your scripts (chicken or the egg…)
http://chancecube.com/products/simple-countdown/
For some reason I’m able to get your version to output using commands whereas the one on chancecube.com I couldn’t…
Thoughts?
On January 30th, 2007, Mike said:
Dave, This is an older version of the plugin currently listed on ChanceCube.com. I’m not really sure why you wouldn’t be able to get any output using the newer version. How were you calling the plugin?
On February 6th, 2007, Mikael said:
Looks very nice, but not exactly what I was looking for. How about adding an boolean option that results in the opposite function: display the time since an event happened? This could be used for things like “how old was my son when this was posted?”
I imagine that the change to the code would be very small.
On February 7th, 2007, Mike said:
Mikael, it’s unfortunate this plugin doesn’t fit your needs though I’m sure there is one out there that does. Displaying the time since an event would take a completely new set of time calculations.
On April 23rd, 2007, Steve C said:
I love it. I had a bit of trouble getting things formatted correctly. I thought I’d post by entry that is working beautifully. Nice Work Mike.
Countdown to the NFL Draft’);
?>
I inserted the H2 to format the title with my current theme.
On April 24th, 2007, Mike said:
Thanks Steve, glad you like it and that it’s working well for you.
On June 16th, 2007, lluxus said:
hey mike, could you please take a look at my problem. i uploaded the .php file to my plugins folder. i activated it, and i want to see it in a single blog-post.
the command i used is: “<!–cc_countdown:06/24/07–>”
the error message is:
Warning: preg_replace(): Unknown modifier ‘2′ in […]plugins/cc_countdown.php on line 169
what did i wrong?
thanks and greets
On July 30th, 2007, Zim said:
Thanks, I’ll try to make it fit my spanish weblog :)
On January 15th, 2008, Tim said:
Ok, need alittle help I guess. I put the files where they go, called the plugin in my sidebar. After much tinkering to get it to stop returning a parsing error, now it just doesnt show up at all. Any thoughts?
On January 27th, 2008, Joan said:
Thx man ;), that’s great.
On April 3rd, 2008, Frank said:
Thanks for the great plugin! With some slight modification I got it working.
I removed:
– the tags
– $output .= ‘’;