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 [] (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>. */ }


  1. nitin [2011-08-17 22:19:07]

    Thanks. I like the idea of tweaking ERP to take "category" as a consideration. You're blog is really cool, BTW.

  2. Gwyneth Llewelyn [2011-08-17 13:12:43]

    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 & how to tweak ERP to find related posts by category and not only by tag ... :)