Subcategories title in category or blog view with multiple columns in Joomla

First of all thanks to Viktor which helped me a lot defining the final solution. You can find his post here.

Now his tricks works well if you have only one column that shows your articles. Now what if your category view shows 3 or 4 columns? You need to tell Joomla to have a line break when you switch to a new subcategory and that’s the tricky part.

We still need to tweak the following files:

Blog View

/components/com_content/views/category/tmpl/blog.php

Category view

/components/com_content/views/category/tmpl/category.php

Blog view

/templates/[your-template]/html/com_content/category/blog.php

Category View

/templates/[your-template]/html/com_content/category/category.php

On the following examples we’ll work with the file category.php on Joomla 3.4.1. The tweak should be very similar though on Joomla 2.5 or 3.3. This tweak works only if you don’t have any leading items. The following example is based on a 4 columns page.

Look for this line

</div><!-- end items-leading -->

This is the end of the leading items section and therefore the beginning of the standard articles section.

Just after 

$counter = 0;

Add the following lines:

$rowcount = 0;
$firstiteration = true;

This will be used instead of the regular $rowcount iteration.

Now comment out the line

$rowcount = (((int) $key) % (int) $this->columns) + 1;

and replace it with

$rowcount++;

After the row

$row = $counter / $this->columns;

And this:

$this->item = &$item;
$subcat = $this->item->category_title;
if ($subcat != $psubcat) :
$rowcount = 1;
$rowcountbeingreset = true;
endif; if ($subcat != $psubcat) :
if ($firstiteration == false){
?>
</div><!-- end row custom -->
$firstiteration=false;
echo "<div style=\"width:100%\"><h2>" . $subcat . "</h2></div>";
endif;
$psubcat = $subcat;

That will basically replace the automatic row counting system and instead create Title for subcategories and line break before each title.

And that’s it! Trick’s done. You can request a zip copy of the PHP file here if that can be of any help. Happy tweaking!