WordPress Archive Calendar Widget
One of the most addicting aspects of Open Source software is the ability to scratch one's own itches.
I've been blogging since 2004 - and while I'd never mistake longevity for expertise - I do take a certain pride in letting my readers know that I've spent over a decade bashing out words.
So, I decided to build a simple widget which would display my posting history in a calendar style. And now, it's time to release it to the world!
It's available on GitHub and the official WordPress plugin site.
What It Looks Like
It's a simple WordPress sidebar widget - displaying the archive as a table.
How It Works
Getting all the months which have published posts within them is pretty simple:
$query = "SELECT YEAR(post_date) AS `year`,
MONTH(post_date) AS `month`,
count(ID) AS `posts`
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
GROUP BY YEAR(post_date), MONTH(post_date)
ORDER BY post_date ASC
LIMIT 256";
It returns each month with an associated year and number of posts - e.g.
array(
array('year' => '2004','month' => '5','posts' => '5'),
array('year' => '2004','month' => '6','posts' => '3'),
array('year' => '2004','month' => '7','posts' => '1'),
array('year' => '2006','month' => '4','posts' => '1'),
array('year' => '2006','month' => '11','posts' => '1'),
array('year' => '2007','month' => '11','posts' => '4'),
array('year' => '2007','month' => '12','posts' => '5'),
array('year' => '2008','month' => '1','posts' => '2'),
...
It's then just a case of iterating through the array and constructing the tables.
Future Developments
- Colour Picker - I'm no æsthete, so people may prefer to choose their own colour scheme.
- Sorting - allowing reverse date order.
- Font sizes - on a smaller sidebar, the longer month names wrap.
- Tests - because why not :-)
- Better CSS - not my strong suit!
- i18n - some people have the temerity to speak languages other than English. Savages!
The source code is available on GitHub and the official WordPress plugin site.
eurydice13 says:
Cool calendar for those who had the presence of mind to use wordpress (or any blogging engine) from earlier on. Feeling bitter that all my pre-2012 posts (dating back to 1998) are not on my current blog. That'd have looked nice & smug. 🙂
Terence Eden says:
Thanks 🙂 I'll let you into a little secret... I imported most of my old blogs (from blogger and other platforms) into this one!