blog.humaneguitarist.org
tweaking Efficient Related Posts, a WordPress plugin
[Mon, 20 Dec 2010 06:12:57 +0000]
There are so many plugins for WordPress that it's easy to get carried away and install more than necessary. I hope I've avoided that. I try to limit myself to plugins that can really improve the reader's experience. The other day, I installed Efficient Related Posts [http://wordpress.org/extend/plugins/efficient-related-posts/] (0.3.6). It's a great tool to generate a list of hopefully related posts on my blog. There should even be some listed below this post. ;) Under the settings, you can alter what the header says and even have it auto-generate related posts for every blog post. For example, I changed the header "Related Posts" to "Related Content". But one thing I didn't see the settings offer is a way to hide that header in cases where no related content was generated. In other words, when no related content was generated it was displaying something like "Related Content: no related posts found." I don't want people to see that so I tweaked the code in the main plugin script using WordPress' plugin editor. Here's the code below. It's only a minor change for the "if" block that starts at around line 307.
if ( !empty($settings['title']) && !empty($relatedPosts)) {
$output = "--------------<h4 class='related_post_title'>{$settings['title']}</h4>{$output}";
/* Nitin Arora modified the code above on 20101219 to display differently.
By adding the "&& !empty($relatedPosts)" condition, only posts/pages with related content
will show the related content header.
A few "-"s were added to offset the related content header for readability.
Also, the <h4> tag was originally an <h3>. */
}
COMMENTS
Thanks. I like the idea of tweaking ERP to take "category" as a consideration. You're blog is really cool, BTW.
Thanks for this article, I had pretty much the same question (although 0.3.8 should now have an "empty" feature). Now I just need to figure out http://xavisys.com/support/forum/efficient-related-posts/wordpress-3-1-appears-to-break-efficient-related-posts/ & how to tweak ERP to find related posts by category and not only by tag ... :)