Auto-blogroll plugin
Now that I’ve written it, I’m sure other folk have written more accomplished versions. Still, here goes.
In conversation with young Miss Pickard (of Little Red Boat fame) the subject of blogrolls arose.
“Ooh,” I typed. “Wouldn’t it be great if there was a plugin that built a blogroll automatically from those who’d left comments on your site?”
Ignoring Anna’s less than enthusiastic response, I set to it and this is the result:
<?php
/*
Plugin Name: Em3 My Friends
Plugin URI: TBA
Description: A plugin that links to regular commentors
Author: Em3
Version: 0.01 pre-pre-beta
Author URI: http://a-fresh-start.a-blog.org/
*/
function show_friends($num=30,$minposts=5) {
global $wpdb;
$friends = $wpdb->get_results("SELECT DISTINCT comment_author_url, comment_author, count(comment_author) as number FROM $wpdb->comments WHERE comment_approved='1' and comment_author_url <>” group by comment_author_url, comment_author order by number desc, comment_author LIMIT 0, $num”);
echo “<ul>”;
foreach ($friends as $line) {
if($line->number > $minposts) {
echo “<li><a href=\”".$line->comment_author_url.”\” title=\”".$line->number.” comments\”>”.$line->comment_author.”</a></li>”;
}
}
echo “</ul>”;
}
?>
As a default it’ll show the top 30 commenters ($num) who’ve left at least 5 comments ($minposts) if they’ve left a URL to link to. I have had to tidy up a few of my friends’ URLs to amalgamate slightly different spellings and cope with changes of domain name but that didn’t take long - a simple query in phpMyAdmin along the lines of:
UPDATE 'xxx_comments' SET comment_author_url = 'http://whatever.com' WHERE comment_author='Charlie'
does it in no time.
To use the plugin, do the old copy/paste/save in wp-content/plugins malarkey, activate it and call <php show_friends(); ?> in your sidebar.
For example, in my sidebar I now have:
<li><h2>My friends</h2>
<?php show_friends(); ?>
</li>
Enjoy.
Modified
Author
Daisy says:
Added on May 1st, 2006 at 7:46 pm“Ignoring Anna’s less than enthusiastic response, I set to it and this is the result”
Hahaha. It’s a good idea code wise, not sure if I’d want to “rate” visitors that way? ‘Cos you know, I loves evwybody equally and all that. And besides, one of these days I’m going to implement the tea themed blogroll (’cos no-one seems to realise that all those weird categories are blends of tea and each blogger was hand matched personality wise to the characteristics of the tea…)
Em3: In version 0.02, then, I’ll have a sort option you can specify as alphabetic or by number of comments. Good idea, Daisy bach. I knew they were blends of tea, by the way. As a non-tea drinker, though, the subtleties are completely lost on me.
Croila says:
Added on May 1st, 2006 at 7:50 pmHmm, rather nifty Em! I’ve never heard of anyone else doing this … Maybe your plugin is unique??
Em3: Thanks. I wonder whether grumpybloke will be next to comment … wouldn’t it be spooky if he was?
Gordon says:
Added on May 1st, 2006 at 8:32 pmGosh, this is almost enough to get me to switch to using WordPress comments… except for all that nasty spam stuff..
And who you calling grumpy!… ohh.. I see..
Em3: As it happens, there’s a post prepared for tomorrow dealing with combatting spam, Gordon …
Daisy says:
Added on May 2nd, 2006 at 5:02 pm*perks up at the mention of the comment spam post*
Am coding like mad at the minute but alas not my own but as soon as I’ve fixed the archive page etc. I’ll come back and have a wee gander at the plugin, thanks Em³!
Croila says:
Added on May 3rd, 2006 at 4:03 pmUm. I want to try this, but being technically inept, I don’t know what I should paste your code into. I mean, it’d be a .php page that goes into the plugins directory, but what should it be called? Would it even matter what it’s called? I don’t really know how plugins work …
Croila says:
Added on May 3rd, 2006 at 4:14 pmDrat. I can’t get it to work. I wonder if there’s a backslash error somewhere? The error message i’m getting is this:
Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /homepages/20/d83833873/htdocs/Croila/wp-content/plugins/showfriends.php on line 17
Parse error: parse error, unexpected T_STRING in /homepages/20/d83833873/htdocs/Croila/wp-content/plugins/showfriends.php on line 17
If you could shed any light, that would be brilliant!
cheers
PS: Have I knocked Daisy off top spot yet???
Em3: The problem’s not with backslashes but, rather, with Wordpress being ‘clever’ with the single and double quotes - they should all be ” or ‘ rather than all those silly “ ” ‘ ’ marks. I only hope this comment displays properly!
I’m going to regret this, but if you hover your mouse over the list ofd friends it’ll tell you how many comments there are … you’re 14 short of top place.