I want to implement different font colors on my taxonomy terms. I have installed and configured my color module version 7.x-1.0-rc1 but still I can't find any result.
-
How many taxonomy terms do you expect? and are you planing for automated colors rather than fixed colors for each term?– Mohammed ShameemOct 10, 2013 at 5:32
-
I actually want a fixed color for each item. I have 2 terms, for my "status" taxonomy vocabulary– user2658838Oct 10, 2013 at 5:36
-
Why don't you use css then. Each term would have its own class you can use that to set a color.– Mohammed ShameemOct 10, 2013 at 8:14
-
Sound simplier.How can I achieve that? what css page will I edit and where will I declare the classes on each taxonomy term?– user2658838Oct 10, 2013 at 8:18
-
If you look at the generated html code you would see the classes for the terms. You can use that classes to define the color in the css of your theme.– Mohammed ShameemOct 10, 2013 at 8:19
1 Answer
Here are steps you need:
Install jQuery Colorpicker module.
In the vocabulary for terms for which you want to add colours, add a jquery color picker field.
So when you create each term, you also select a colour for it while creating. in this way each taxonomy term will have a colour.
now in the taxonomy term preprocess template, write something like this to grab the color and pass it as variable.
function themename_preprocess_taxonomy_term(&$vars) { $colour_code = $vars['taxonomy_term']->field_yourcolorfieldname['und'][0]['value']; $vars['colour_code'] = $colour_code; }
Then copy the taxonomy-term.tpl.php to your theme folder, and you will be having $colour_code variable giving you the colour code of the term. you it to provide an inline css.
Remember, if overriding taxonomy term template is not what you need, or you want to have it elsewhere, whenever you get $term object, you can get the colour code through $term->field_yourcolourfieldname['und'][0]['value'].
-
-
Where can I find this "now in the taxonomy term preprocess template" Oct 10, 2013 at 8:36
-
copy /modules/taxonomy/taxonomy-term.tpl.php to you theme. Them modify the copied taxonomy-term.tpl.php file– NeoOct 10, 2013 at 8:38
-
And for your preprocess funciton, you need to implement the themename_preprocess_taxonomy_term(&$vars) function i wrote in your theme's template.php file. Ofcourse replace 'themename' with the name of your theme.– NeoOct 10, 2013 at 8:39
-