I want to be able to assign a color code to seperate articles.

Such that the border or background of an article changes color, like; Article A = Purple Border Article B = Green Border Article C = Red Border

My own idea is to make an alternative layout, and use one of publishing fields to insert the color code and pull the color in the code.

It's important that I can use the color in both article layout, but also article category layout, so I color each article link, it's assigned color.


You will need to create a Template Override for the article and category views.

This may not be a preferred method, however it's what I would personally do.

Category view:

So once you have created your overrides for both views, in the category view, add the category ID as a class to the element for the title. For example:

<div class="id_<?php echo $item->id; ?>">
    <p>The category title will be here</p>

Which will result in the following markup

<div class="id_2">
    <p>Category title</p>

Article view:

Now in your article view, use something similar in your override as shown below:

<div class="id_<?php echo $this->item->catid; ?>">
    <p>The article title will be here</p>

Which will result in the following markup

<div class="id_2">
    <p>Article title</p>

You can then target each class, in this case id_2 in your CSS file like so:

.id_2 {
    border: 1px solid #F00;

Hope this helps

| improve this answer | |
  • Okay, so this works off the article ID, which is incremental, correct? so I can create a CSS class like .green and assign it that way. I have to create articles, find their article ID and reversely create the fitting CSS class? If I can pull Article ID, can't I just pull the "created by alias" or "author" and have them be colors? I don't plan on showing authors anyway. – Dsan Jan 15 '15 at 12:05
  • No, you're not getting the article ID, only the category ID. Yes, you can use the author instead if your wish – Lodder Jan 15 '15 at 12:09
  • What/where would define category ID then? For using Author, is it just <div class="id_<?php echo $item->author; ?>"> instead? – Dsan Jan 15 '15 at 12:31
  • Look at the code in my answer. – Lodder Jan 15 '15 at 12:32
  • I worked it out, thanks a ton :) I'm using color_<?php echo $this->item->created_by_alias; ?> and then just put "green" in the created by alias field and style appropriately. for the Category list, it's just color_<?php echo $item->created_by_alias; ?> Thanks Lodder :D – Dsan Jan 15 '15 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.