Archive for July, 2005

Making monthly archive dropdown lists in WordPress

30 July 2005

I was asked by Armand how to do the month-by-month blog archive drop-down in the right hand column of the blog, which, if you have archives going back some time, saves having an enormous list of months (which, IMHO, looks ugly). WordPress’s get_archives() function does provide drop-down capability, but only by using JavaScript to handle the form submission, which is just dumb, and breaks badly if you don’t have JavaScript enabled.

So, I wrote a hack that does the drop-down, but handles it using standard HTTP form submission (which is nice). There is a bit of JavaScript, an event handler to submit the form straight away when a selection is made, but this is a convenience thing, and it still works the old-fashioned way if you have JavaScript disabled.

Here goes… first of all it’s just a hack, not a plugin, so you’ll need to have a my-hacks.php file set up and running – see here for more details.

Once you have my-hacks.php open, add the following inside the PHP code:

function make_month_dropdown() {
	global $wpdb, $tableposts, $month;
	$now = current_time('mysql');
	// Get the entries grouped by month and year
	$archiveEntries =
		$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`,
		MONTH(post_date) AS `month`
		FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish'
		GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
	// Start form
	echo '<form action="'.get_settings('home').'/" method="get">';
	echo '<div><select name="m" class="small" onchange="this.form.submit();">';
	// Produce each line of the dropdown
	foreach($archiveEntries as $archiveEntry) {
		// Add leading zero
		$thisMonth = zeroise($archiveEntry->month,2);
		// value to be passed into query string
		$thisM = $archiveEntry->year.$thisMonth;
		echo "<option value=\"$thisM\"";
		// Preselect currently-viewed month
		if ($thisM == $_GET['m']) echo ' selected="selected" ';
		echo '>';
		echo $month[$thisMonth].' '.$archiveEntry->year;
		echo '</option>';
	}
	echo '</select>&nbsp;';
	echo '<input type="submit" value="&raquo;" />';
	echo '</div></form>';
}

Save that (and upload). Then in your template file (sidebar.php), replace the line beneath the archive header, that says <?php get_archives(); ?> (or something similar) with:

<?php make_month_dropdown(); ?>

And you should be done. Hopefully. Feedback in the comments below.


Serious but not organised

29 July 2005

A few weeks ago Mayor of London blog spotted a loophole in the 2005 Serious Organised Crime and Police Act that, although it created a big chunk in Westminster which made it illegal to commence protests without permission, Brian Haw‘s ongoing protest was exempt.

At the time I thought it was an amusing story which I would relate down the pub and then promptly forget (which I did), and that it had no chance as a successful legal defence. Until today that is, it turns out Brian Haw has succeded in getting exempted for that very reason. Which is a good thing. But only a very small good thing. The legality of the Act is not in question, so the rest of us can’t join in, and Parliament could happily amend the Act to cover past protests if it wanted to, so there’s no guarantee that Mr Haw will be safe forever.

More scarily, though this error works out in the favour of those of us who cherish democracy, we must remember that it slipped through in the rush to get the Bill passed before the election, which meant it didn’t come under the scrutiny it might otherwise have had. Which leads to the question – what about all the other parts of the bill? Did the muppet who drafted the clauses about the protest part get his hands on the rest of it, the bits that actually had to do with serious organised crime? And what about all the other bills passed at the same time? I shudder to think…


Free as in beer, not as in software

28 July 2005

Must be a slow news day or something – the story about Open Source beer banging around various weblogs and linklogs I read. Okay, so the idea is great, make a beer recipe with a Creative Commons share-alike licence which people can download, use for free, make derivative works, etc.

But, it’s nothing more than a crappy gimmick. For starters, the recipe they have isn’t that much more informative about making beer than what’s currently available in the public domain, or on other websites (this brewing site, which I found while Googling, looks quite interesting, and is far more informative). More importantly, the knowledge required to brew beer successfully is not the kind that benefits from an open-content licence; it’s highly complex and often quite tacit – what the different strains of yeasts, varieties of grain and their carbohydrate content, the time of year and ambient temperature, the complicated business of sterilising containets – all these factors are quite hard to get a handle on and to make things worse, the complexity increases once you start combining them.*

These things are hard to spell out exactly. To publish a beer recipe is an amusing diversion, but on its own, it’s about as informative as posting source code without comments, if not worse – all the information of any use is outside the grasp of the written word.

* I am not a brewing expert; however my father used to be quite into making wine, sherry and later on, mead, and I suspect many of the problems he encountered similarly apply to the beer industry.


Greasepostmonkeycoding

27 July 2005

Oh no, I broke the golden rule and started mucking around with Greasemonkey, which was a mistake, as I have now wasted this entire evening. Anyway, it is fun to play with custom code in webpages, and after basically looking at other people’s code I’ve come up with a simple little widget – it turns any UK postcode in a page (which is not already inside a hyperlink) into a hyperlink to the relevant Google Maps map for the area – e.g. SW1A 2AA becomes SW1A 2AA. Want to try? Install it from here (you must have Greasemonkey installed first, obviously – download it here). Enjoy. Lots of it is derived from others’ work – credits are in the source code. Any bugs, report in the comments below.


Fair use of ripped CDs, and charity shops

27 July 2005

While dropping by my local Oxfam bookshop today, I noticed a wee notice in the door that said along the lines of: “Upgraded to an MP3 player? Then why not donate your old unwanted CDs to us?” While this is perhaps an eminently nice sentiment and innocuous to boot, to me this looks like it might break copyright law. For while ripping personal copies of your own CDs onto MP3 for use on the move or as backup falls under “fair use“, if the original then moves into someone else’s hands, as the MP3 is no longer a duplicate of something you own, it’s no longer fair use and so your copy is illegal. I think. (I am not a lawyer, after all) Of course, while selling on the old CD is probably a definite no-no, I don’t know whether donating it to charity is the same, but I think it might be – and you know how horrible intellectual property lawyers can get. Anyone care to advise?


We Are Afraid!

27 July 2005

While We’re Not Afraid! was a bit, in my opinion, tacky, and bordering on a sort of online equivalent of grief tourism, at least the sentiment was eminently agreeable; we should not be afraid of stepping out in public, nor should we suspect anyone whose skin isn’t white of being about to kill us.

Bolstered by this, I thought that the people of London would be broadly in agreement. But then I read this BBC article on how non-white Londoners are getting funny looks, or even outright hostility, when they travel now; the fact that they now feel compelled to ‘blend in’ to a city that is characterised by its diversity is quite perverse (although the guy who now wears a white wristband and carries a copy of the Economist brought a smile to my face – he’s savvy enough to be covering all bases, at least).

I didn’t see many travellers actually treating others with outright suspicion whilst bounding round on the tube and buses this weekend, which might mean this all may be a figment of the receiving party’s imagination; they could be worried enough that they’re actively looking for hostility from fellow travellers and are merely projecting fear onto others, but if anything this is worse. Either way, it means that a significant number of people are now getting properly fucking scared of one thing or another, which means that the terrorists are winning – sorry, I hate that phrase, I’ll go again – which is a horrible state of affairs that becomes very hard to remedy. What can we do about it?

Update: Whatever we do about it, it won’t be thanks to any ideas from the letters page of Metro (which makes the BBC’s “Have Your Say” look like The Moral Maze). Going Underground carries a selection for today, including one person who suggests fostering community spirit by having luminously-jacketed volunteers who would demand to inspect the contents other passengers’ bags. Nurse!


Pages: 1 2 3 4 5 Next »