Wordpress Plugin: Simple Countdown

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”

Download Version 1.0.1

Example: (Sorry, Lunch on January 1st 2012 is already over)

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 h5 element 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 FALSE when the event has passed “(Your event title) has already happened” will display wherever the plugin is called. Default is TRUE.

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_countdown instead of ms_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.

Reader comments

  1. Gravatar

    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.

  2. 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.

  3. Gravatar

    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

  4. 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 loop it 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).

  5. Gravatar

    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

  6. 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.

  7. Gravatar

    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?

  8. 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_TITLE with the title you’d like to use and 12 june 2006 with the date your counting down to.

    One example of the plugin would be at the top of the sidebar on this site.

  9. Gravatar

    On August 3rd, 2006, John said:

    Thanks that did it.

  10. Gravatar

    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.

  11. Gravatar

    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?

  12. 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?

  13. Gravatar

    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.

  14. 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.

  15. Gravatar

    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.

  16. On April 24th, 2007, Mike said:

    Thanks Steve, glad you like it and that it’s working well for you.

  17. Gravatar

    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

  18. Gravatar

    On July 30th, 2007, Zim said:

    Thanks, I’ll try to make it fit my spanish weblog :)

  19. Gravatar

    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?

  20. Gravatar

    On January 27th, 2008, Joan said:

    Thx man ;), that’s great.

  21. Gravatar

    On April 3rd, 2008, Frank said:

    Thanks for the great plugin! With some slight modification I got it working.

    I removed:

    – the tags
    – $output .= ”;

  22. Gravatar

    On September 6th, 2008, Cindy Washam said:

    Hello, can I see an example of your countdown creation? Have I overlooked an example on this page?

    Goal: I need one for an upcoming RC Race in October and would like to see if this would suit the event on our main page.
    Thank you,

  23. On September 6th, 2008, Mike said:

    Cindy: I’ve updated the post to show an example. Another example can be seen on my personal site, /mike in the sidebar (my birthday countdown). :)

    Hope it’s what you’re looking for.

  24. Gravatar

    On January 30th, 2009, luca said:

    does this work with WP 2.7?
    I followed your instruction to add the code into a Post, I added this:

    < ! --cc_countdown:EVENT DATE AND TIME, EVENT TITLE-- >

    In the cc_countdown.php I entered:

    function cc_countdown($eventDate = ‘12 june 2010′, $title = ‘RADUNO’, $autoDelete = FALSE, $inPost = FALSE, $inline = FALSE)

    The post keeps stating:

    (Sorry, EVENT TITLE is already over)

    Can you help? What am I doing wrong?

    Regards,
    Luca

  25. On January 30th, 2009, Mike said:

    Luca: I haven’t tested this plugin with WP 2.7 yet. A couple pointers though:

    In the post use this code: cc_countdown:"12 june 2010", "RADUNO". The event details should be made here instead of in the plugin file itself.

    Change the function cc_countdown back to its original state. This file should not be changed (unless it’s updated). Event specific information shouldn’t be included in this call.

    Try those suggestions and let me know if it helps or let me know if there are any other problems.

  26. Gravatar

    On January 31st, 2009, luca said:

    I followed your instructions and I entered the future date in the Post, but it keeps telling me Sorry, RADUNO is already over.

    I entered the date in this format:

    January 1 2012
    1 1 2012
    2012 1 1

    No way, it does not work. :(

  27. On February 10th, 2009, Mike said:

    Luca: Sorry that didn’t work. As I said, this plugin hasn’t been tested in WP 2.7 and probably won’t be. I haven’t had much time or desire to update this plugin. Your best bet would be to see if someone else would be interested in updating it for WP 2.7 or finding a different plugin.

Leave a comment