Joomla Latest Articles Hack

Do you use the Joomla Latest Articles module (as I do) to display your latest articles as a module? Do you also find that the titles can sometimes run onto a second line, spoiling the layout?

I wanted to limit this effect and after a bit of searching I found some info that I was able to adapt to do exactly what I wanted, in other words, if an article title was too long to display on one line, a little code would resolve the issue.

In your Joomla 3 admin pages, go to your templates, choose the template you are using for your site, then click on Create Overrides. You need to create an override otherwise the next time Joomla updates itself, you run the risk of losing your changes if you use the original file.

The override you want to make is under Modules, find and click on mod_articles_latest. If you haven't already created an override file, this will create one that you can amend. This new file will be found under the Editor tab, in html>mod_articles_latest>default.php

Click on this file and in the editor window, look for this line: < ?php echo $item->title; ? >

Change it to < ?php echo (strlen($item->title) > 30 ? substr($item->title,0,30).'...' : $item->title); ? >

Substituting both 30's for the maximum number of characters you wish your Latest Article Module to display. There should be no spaces between "<" and "?" or "?" and ">" in your editor by the way, there are here only to show up as text otherwise they would be translated into php and crash the page.