For the last door in our Advent Calendar I had something special in mind. This year is coming to an end and I'm sure some of our readers want to quit smoking next year. To support their goal, I created a WP Engineer Quit Smoking Widget. 😉
Here a screenshot of all setting possibilities:
And this is how it would look like on your blog:
Even though, this idea seemed to be easy to realize. It was a piece of work. I don't want you to be bored, so I'm not explaining the whole code, but I just want go in detail on some details, what I had to consider to make this Widget workable.
I check the date if it's valid ( 2009/02/30 doesn't exist). Then I had to avoid division by zero, if the Widget is active but doesn't include any values yet. For the correct formatting of the saved money depending on the language I used the WordPress function number_format_i18n:
$saved = number_format_i18n($packs * $price, 2);
Unfortunately, there is no feature in WordPress, which displays the currencies correctly (but I guess, this is probably not necessary). Therefore, I added a field "Currency position" with the values "before" and "after", so that the currency will be displayed properly, depending on the country. The year field automatically displays the current year minus 5 years, so that the widget is also current in 100 years. 😉
The rest are fields for entering the text output before and after values.
Unzip file wpe_quit_smoking_widget.zip and copy it to wp-content/plugins/ , then activate it in your backend. After that the Widget will be available in your Widgets area.
Please Note: The Widget needs WordPress Version 2.8 or higher, otherwise it won't be displayed.
Download WPEngineer Quit Smoking Widget
Have fun with the Widget and good luck with your goal to stop smoking! The team of WP Engineer wish you all Happy Holidays!