Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom class css in entry-category html tag
Tagged: category
- This topic has 7 replies, 2 voices, and was last updated 7 years, 9 months ago by William.
-
AuthorPosts
-
June 28, 2016 at 3:10 pm #188486FurlazMember
Hi,
I would like to integrate a custom class css in my html tag entry-category.
I need to do a custom class css in term of the category.Exemple :
- If my actual category (for the current post in the loop) is "actuality", I would like to have a class "actuality-category" for exemple.Is it possible ?
Thanks for your help 🙂
June 29, 2016 at 12:06 am #188499WilliamMemberYes it is possible 🙂
//* Add a class to the category add_filter( 'body_class', 'my_body_class' ); function my_body_class( $classes ) { if( is_category( 'my-category') { $classes[] = 'my-class'; return $classes; }}
This will add a class to the BODY element.
Paste it your functions.php file!
Genesis Customization Service | Quick fixes whenever you need them ! | Contact me at Fixmysite.com !
June 29, 2016 at 1:49 am #188502FurlazMemberHi William,
Thank you very much for your answer 🙂
I had seen this code on the studiopress (I searched before lol)In my case, I would like to change the background-color for each category tag on my home page (with the list of my posts).
So, if I change my body class, the change will be for the whole page and not every post.Is it clear ? (I'm not bilingual ^^)
June 29, 2016 at 1:59 am #188503WilliamMemberAhh... I get it!
You can do that with some basic CSS, if you send me a link to your website - I will have a go at it !
Genesis Customization Service | Quick fixes whenever you need them ! | Contact me at Fixmysite.com !
June 29, 2016 at 2:02 am #188504FurlazMemberIf you have an idea, I say yes 🙂
It's a website for a cliente (it's on a developpement environnement) : http://emetjen-dev-nounoune_et_ses_tifs.pf3.wpserveur.net/
Actually, I changed the background color of my all category tag but now, I would like a different color depending on the category 🙂June 29, 2016 at 3:00 am #188508FurlazMemberI have a track. I found this : http://victorfont.com/genesis-framework-add-a-custom-css-class-to-elements/
With this element "genesis_attr_entry-meta-before-content", it add a custom class perfectly where I want.
Now, I just need to detect my category for each iteration of the loop... possible ? 🙂June 29, 2016 at 3:59 am #188510FurlazMemberIt's me again 🙂
I found !!
I use this function ://* Add a custom class add_filter( 'genesis_attr_entry-meta-before-content', 'ldw_my_custom_class' ); function ldw_my_custom_class( $attributes ) { if ( in_category('category-1') ) { $attributes['class'] = $attributes['class'] . ' category-1-class'; } else if ( in_category( 'category-2' ) ) { $attributes['class'] = $attributes['class'] . ' category-2-class'; } else if ( in_category( 'category-3' ) ) { $attributes['class'] = $attributes['class'] . ' category-3-class'; } if ( is_category( 'category-1' ) ) { $attributes['class'] = $attributes['class'] . ' category-1-class'; } else if ( is_category( 'category-2' ) ) { $attributes['class'] = $attributes['class'] . ' category-2-class'; } else if ( is_category( 'category-3' ) ) { $attributes['class'] = $attributes['class'] . ' category-3-class'; } return $attributes; }
And it works perfectly !
Thanks for your help William 🙂
June 29, 2016 at 4:33 am #188511WilliamMemberPoem 🙂
Genesis Customization Service | Quick fixes whenever you need them ! | Contact me at Fixmysite.com !
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.