This is a template override for Joonla 2.5 to split Category blog layouts by category with their respective titles. Joomla 2.5 does sort the articles by categories if instructed to do so in the menu item's options, but it does not display the Subcategory titles when needed. I couldn't find an extension to do that. A simple layout override is enough however.


The file to override is the one at /components/com_content/views/category/tmpl/blog.php

To tweak it safely (and avoid it being overwritten by an update of Joomla) copy it as /templates/[your-template]/html/com_content/category/blog.php If the appropriate subfolders do not exist in your template's folder, create them.

Then find the line which says

<div class="items-row cols-<?php echo (int) $this->columns;?> <?php echo 'row-'.$row ; ?>">

That was line 78 at the time of writing. Just above that, insert the following:

$this->item = &$item;
$subcat = $this->item->category_title;
if ($subcat != $psubcat) :
echo "<h2>" . $subcat . "</h2>";
$psubcat = $subcat;

What it does (and its limits):

  • This is inserted in the loop which displays the intro articles. I don't use leading articles and links. If you need that. you can probably tinker with the foreach loops before and after that one.
  • There are two variables: $subcat stores the category title of the present article, and $psubcat remembers it until next loop. $subcat and $psubcat are compared and if they differ (if it's the first article of that category), the title is displayed.
  • This will change the display of all category blogs on the site.
  • It may require somme fiddling with the options to "Show category titles" in the menu items.

If you end up with a more flexible approach, please email me.