atypisch

atypisch supports this item

Supported

Popular questions for this item

I have installed the Category Colors plugin and added custom colors to my categories. Only I’m not a programmer, how can I add these colors to my template?

In your theme, find the file where you want the color to appear. For instance, in your theme file ‘single.php’ your single post will be shown. If you go there, find these lines:


<?php if (have_posts()) :  ?>
<?php while (have_posts()) : the_post(); ?>

EXTRA_CODE_BELOW_GOES_HERE

<?php endwhile; ?>
<?php endif; ?>

Don’t edit or remove the above lines, but add these lines in between instead:


<?php  
$category = get_the_category(); 
$the_category_id = $category[0]->cat_ID;
if(function_exists('cc_get_color')) { 
     $category_color = cc_get_color($the_category_id); 
} 
?> 
<h1 style="color: #<?php echo $category_color; ?>;"><?php the_title(); ?></h1>
<p style="background: #<?php echo $category_color; ?>;">Look at my awesome new color!</p>

Now you used the color in your template in an inline stylesheet. The variable <?php echo $category_color; ?> can be used for anything.


You can also use the color in other templates ofcourse, or to color backgrounds, lines, text, etc. For more support on CSS google ‘inline css colors’ or check out some of the basics online at W3 here or here at W3Schools.

When I create a new Category the default color is always a bright green. How can I change this?

Go to Settings -> Category Colors and change your default color there.

Why can’t I pick a color right away when creating a Category, but only when editing a Category?

Both for consistency and efficiency. First of all we want to keep creating Categories sweet and simple with as little effort as possible. Adding Colors can be considered as customizing Categories, thus it would be more logical to show it in the Edit section only.

Second, when writing a Post you can also quick-add a new category. For consistency’s sake we’d have to add the Colorpicker there too, which would be too much of a hassle user-wise at least.

Do you have more code examples? What if I get my categories through the wp_get_post_categories() function in Wordpress?

No problem at all. Just use the ids – array like so:

<?php
$the_category_id = implode(", ", wp_get_post_categories( $post->ID , array('fields' => 'ids')));

          if(function_exists('cc_get_color')) { 
            $category_color = cc_get_color($the_category_id); 
          } 

?>

Since you have the Category ID now you can use that to get the category name for instance with a standard Wordpress function like so:

<?php echo get_cat_name($the_category_id);?>


So, to make a colored Category Name you would do something like this:
<h1 style="color: #<?php echo $category_color; ?>;">
<?php echo get_cat_name($the_category_id);?>
</h1>


I want to change the background color of my Posts per category, how do I do that?

First find these lines in your template files:


<?php if (have_posts()) :  ?>
<?php while (have_posts()) : the_post(); ?>

PASTE THE STUFF BELOW HERE

<?php endwhile; ?>
<?php endif; ?>

Paste this into your template between the lines above:

<?php  
$category = get_the_category(); 
$the_category_id = $category[0]->cat_ID;
if(function_exists('cc_get_color')) { 
     $category_color = cc_get_color($the_category_id); 
} 
?>

<div class="post" style="background: #<?php echo $category_color; ?>;">
     <h1><?php the_title(); ?></h1>
     <div class="entry">
     <?php the_content(); ?>
     </div>
</div>

I want to use multiple Category Colors in one loop, is this possible?

Yes. For this you will need to use the ‘foreach()’ function. One way is to run through each category and output the color within the loop. The example below shows how to loop through the categories and output a list with the category name and color for each category.

<?php
//get the categories
$category = get_the_category();
//loop through all categories
    foreach($category as $the_category) {
    //the category name
    $category_name = $the_category->name;
    //get id for each category
    $category_id = $the_category->cat_ID;

        //now run the Category Color code
        if(function_exists('cc_get_color')) {
            $category_color = cc_get_color($category_id);
                echo "<font style="color: #";
                echo $category_color;
                echo "">" . $category_name . "</font> ";
        }
    }
?>

Show more

Contact the author

This author provides limited support for this item through this item's comments.

Item support includes:

  • Availability of the author to answer questions
  • Answering technical questions about item’s features
  • Assistance with reported bugs and issues
  • Help with included 3rd party assets

However, item support does not include:

  • Customization services
  • Installation services

View the item support policy

by
by
by
by
by
by