As you may or may not know, I recently switched to the Bobbles WordPress Theme from Dezzain.com. It truly is a gorgeous theme and has a very “Web 2.0″ feel to it with a lot of social web integration. In using and exploring Bobbles I came across a bug that I informed the creator of, but I decided to take matters into my own hands and come up with a fix.
The bug is small but nevertheless needed to get fixed. If you were looking at a single post — therefore in the single.php file of the theme — you would see a “Similiar Topics” section with related entries to what you were looking at, but when hovering the mouse over a link you would get the_excerpt() from the current post you were reading. So the solution was to change the code to pull the_excerpt() that corresponds to the title of the related post.
After a few hours of hacking away at it here is the code (in single.php) that I changed to get it working:
Essentially there are three things that need to be done: 1) add the getWords() function between lines 52 and 61 — make sure it’s not inside the foreach loop or else you will get errors as you can only declare a function once; 2) add the variables between lines 63 and 65 — these will go inside the foreach loop because they need to get done for every related post; and 3) change the value of the anchor tag title attribute in accordance with line 67 so that it outputs the final variable $a_title.
If you want to show more than the first 15 words change the number on line 64 to however many words you want to show, and if you don’t want show the three dots (…) after the excerpt just take out . “…” from line 65.
Let me know if you have any questions or experience any problems.