Support Forum

Please note that this forum is only available to you in read only mode. In order to contribute to this conversation you will need to renew your subscription.

PHP Hack for Coloured Category Names

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

Howdy,

I wrote a quick hack for an infinite number of coloured category names. Let me know if anyone would like me to post. Here's my site running the hack:

www.asknelly.com

Cheers,

Bill
  • notsteve's Avatar
  • notsteve
  • 12 Month Developer
  • 119 posts
  • 2 Thanks
  • Karma: 6
The administrator has disabled public write access.
Hi Bill

It would be handy if you could post your solution :)

Cheers
Paul
  • manh's Avatar
  • manh
  • Moderator
  • 45248 posts
  • 2106 Thanks
  • Karma: 603
The administrator has disabled public write access.
OK, here is a quick and easy PHP hack for assigning colors to categories. First, you make the PHP changes. Then, you add CSS in your custom.css file for your colors (including hover colors, etc.).

Here it is in action: www.asknelly.com

Here are the files to modify, and approximately where to start:

html/com_content/article/default.php (Line 142)
html/com_content/category/blog_item.php (Line 113)
html/com_content/featured/default_item.php (Line 111)

Here is the change; it's the same for all three files:
<!-- [CAT COLOUR MOD] BEGIN -->
<?php if ($params->get('show_category')) : ?>	
<?php 
if ($this->item->category_alias)
    echo JText::sprintf( '<dd class="category-name category-style-' . $this->item->category_alias . '">'); 
else
    echo JText::sprintf( '<dd class="category-name>');
?>
<!-- [CAT COLOUR MOD] END -->

Then, you add your CSS. For each category you want to assign a separate color to, create a corresponding CSS class with the following naming scheme:

category-style- followed by the Joomla category name

So, if your Joomla category name is "ferrets" then your corresponding CSS class would be: category-style-ferrets

You can do whatever you want in your own CSS, of course. Below is the code from my site for the first two categories. Add as many categories as you want; just make sure the names match up with the category names you create in Joomla.
.category-style-health a {
  background: #3833BE;
  border-right: 2px solid #0d0980;
}
.category-style-health a:hover {
  color: #fff;
  background: #0d0980;
  border-right: 2px solid #0d0980;
}

.category-style-money a {
  background: #007020;
  border-right: 2px solid #003d12;
}
.category-style-money a:hover {
  color: #fff;
  background: #003d12;
  border-right: 2px solid #003d12;
}

NOTE: In my site, I also added a bunch of CSS to category-name for some more styling that applies to all the category names.

OK, so that's it. Enjoy!

Cheers,

Bill
  • notsteve's Avatar
  • notsteve
  • 12 Month Developer
  • 119 posts
  • 2 Thanks
  • Karma: 6
Last Edit: 10 years 4 months ago by notsteve.
The administrator has disabled public write access.
The following user(s) said Thank You: manh
Thanks a lot Bill

I've made this a sticky :)

+5

Cheers
Paul
  • manh's Avatar
  • manh
  • Moderator
  • 45248 posts
  • 2106 Thanks
  • Karma: 603
The administrator has disabled public write access.
yes please - kim @ kimsingleton . com
  • Kim Singleton's Avatar
  • Kim Singleton
  • 6 Month Developer
  • 30 posts
  • Karma: 0
The administrator has disabled public write access.
Hi Kim,

Have you followed Steve's comments it should do the trick for you

I'd suggest making a copy of the files to be changed first

Cheers
Paul
  • manh's Avatar
  • manh
  • Moderator
  • 45248 posts
  • 2106 Thanks
  • Karma: 603
The administrator has disabled public write access.

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

Happy Campers