I recently got sick of manually entering in the current date, and month for a personal (private) wordpress post that I use to keep basic details of what I’ve done for the day (computer exploded, Zombies attacked, met an awesome girl, etc..).
I actually hadn’t updated it for months because it was too much of a pain, so I wrote a PHP script that outputs the name of the month, the current date, and then an unordered list with some ‘-‘ place holders to stop WordPress from removing the the list.
Please note, that the script is pretty basic, and just shows the next 100 days.
For those that do know what PHP is, you’ll know that you need to actually get a web server (like Apache) to run it. The code is very basic, but shows the power of for loops, and the date, and time functions of PHP.
If you don’t know what PHP is, then don’t worry, just click on the Script button below, then you can copy and paste the contents into WordPress (or whatever blogging program your using), alternatively when you are looking at the script you can right click, and [view page source], or whatever your browse calls it, then copy the raw HTML, and paste that into your blogging program.
Script : http://www.kublermdk.com/web_widgets/Months.php
Code : http://www.kublermdk.com/web_widgets/Months.phps
Sunday 1st :
Monday 2nd :
Tuesday 3rd :
You can download the PHP code from http://www.kublermdk.com/web_widgets/Months.phps (then rename the extension to just .php)
The actual PHP code :
This PHP script was created by Michael Kubler on the 14th January, 2009, for www.kublermdk.com
Feel free to edit this as required.
For any enquiries, email email@example.com
$current_date = time() - (86400 * 3); //Set the date to a few days ago.
for($i = 0; $i <= 100; $i++)
//This sets how many days to view, at the moment it's 100.
$current_date = $current_date + 86400;
if(date("F", $current_date + 86400) !== $current_month) //Display the next month header bit if it's changed.
$current_month = date("F", $current_date + 86400); //I want the month listed before the 1st day, hence the +86400, which is the number of seconds in a day.
echo "\t<p style=\"text-align: center;\">---------------------<br />\n";
echo "\t<strong>$current_month</strong><br />\n";
<span style=”text-decoration: underline;”><?php echo date(“l jS”, $current_date + 86400); ?> :</span>