One of the things I don't like about Michelle MacPhearson's otherwise great Sphinn plugin for WordPress is that it shows a Sphinn button for all posts on my home page and in category pages. While I understand that the button may encourange people to Sphinn an article by making it easier for them to do so, having a bunch of Sphinn It! (i.e. 0 Sphinns) buttons gives the impression of desperation. Instead, I'd rather have the button show only AFTER the first Sphinn. And looking at the comments on Michelle's blog, I'm not the only one that wants this behavior.

This modified code will first ping the Sphinn site and check for the existence of certain text that indicates no Sphinns. If the text isn't found i.e. there is at least one Sphinn, the button is displayed. This code doesn't put any more load on the Sphinn servers than having the button display all of the time so no need to worry about causing Danny Sullivan and his crew any grief. And if the Sphinn folks change the text I'm searching for, this extra code will default to showing the button which is the same out-of-the-box behavior of the plugin.

Warning: I'm not a PHP developer (I just play one on TV) so use this hack at your own risk. Wherever you've modified your theme to include the call to the Sphinn plugin, replace it with the block of code I have below. This requires a theme modification and the use of Method C for implementing the Sphinn plugin as described in Michelle's readme.txt file. This code could most certainly be wrapped into the plugin itself, but I'll leave that up to someone else (if you do include this code in a plugin, I'd appreciate a link).

You can see this modification in action on my home page and on my SEO category page. The same modification could be use on individual posts if you so desire.

BEFORE

<?php show_sphinnit(); ?>

AFTER


<?php
$ch = curl_init();
$url = trim('http://sphinn.com/evb/url.php?url='.get_permalink($post->ID));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
if(stristr($output, 'Sphinn it!') === FALSE) {
show_sphinnit();
}
?>

If this code doesn't work for you, leave me a comment with error details and I'll try to help you out.

If you liked this post, please consider sharing it with others. These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Sphinn
  • StumbleUpon
  • Mixx
  • Reddit
  • bodytext
  • del.icio.us

2 Responses to “How to Show the Sphinn Button Only AFTER the First Sphinn”
  1. Thomas says:

    Works like a charm! Thanks

  2. Marios Alexandrou says:

    Thomas,

    Glad to hear it. I actually there'd be more interest in this modification. Oh well. It just goes to show you that you can't ever be 100% sure what people will like. I hope you hit the Sphinn button after trying it out :-)

Leave a Reply