• Resolved herowp

    (@herowp)


    Hi all. I am developing a wordpress news theme. What I want to do is add custom color to each category. At the end of the category template I have the following code, which works fine. This code add custom colors for each category (When user create a category, it choose a background color – I added an extra field there)

    <?php
    	$category = get_queried_object();
    	$category_id = $category->term_id;
        $cat_data = get_option("category_$category_id");
       if($cat_data['catBG']){
    ?>
    <style>
    some css code
    </style>
    <?php  }?>

    So far so good, but for example, if a user click a news inside the Sports Category (which background is green), when in the news single section, the css code returns to default (which color is red). I want the green css, for the news (inside the spors category) as well.

    I hope what I said it make sense.

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter herowp

    (@herowp)

    Solved it myself, added this code at the end of single.php

    <?php
    
       $category_name = get_the_category();
       $a=get_cat_ID( $category_name[0]->cat_name ); //category id
    
       $cat_data = get_option("category_".$a);
    
       if($cat_data['catBG']){
    ?>
    <style>
    some css
    <?php  }?>
Viewing 1 replies (of 1 total)
  • The topic ‘Add custom css for each post inside a category.’ is closed to new replies.