Call Us Now at +1.403.536.9877 or fire us an email for a free quote

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

Posted by Bruno
on 17 June 2015

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

Of course you shoud not edit directly those files but create overrides in your theme folder:

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;

Add 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'll find a zip copy of this php file here if that can be of any help. Happy tweaking!

Leave your comments

Post comment as a guest

0 / 2000 Character restriction
Your text should be in between 20-2000 characters
terms and condition.