Title: Category page class
Last modified: September 1, 2016

---

# Category page class

 *  Resolved [woober](https://wordpress.org/support/users/woober/)
 * (@woober)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/)
 * How would i add a css class to all products in the category page, if they are
   a specific product category?
    E.g. im seeing alle products in the category page
   and i want all the products in Men category to get an extra class in the category
   page
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Caleb Burks](https://wordpress.org/support/users/icaleb/)
 * (@icaleb)
 * Automattic Happiness Engineer
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644249)
 * There should already be a special body class. Look at the html. For example, 
   I have a “Clothing” category on my demo site and I found these on the body tag
   in the html: `tax-product_cat term-clothing`
 * So you can just target those specific products on the category page like so: `.
   tax-product_cat.term-clothing li.product`.
 *  Thread Starter [woober](https://wordpress.org/support/users/woober/)
 * (@woober)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644256)
 * Thanks for the reply.
 * It shows the category page im in and not the category-classes which are within
   the category.
 * E.g If Men & Women category has clothing category as parent, then if i enter 
   clothing, then i dont see Men or Women class in the body + the i want the Men
   products to have a class, not the body.
 * `<ul class="products"><li class="men">`
 *  [Thomas Shellberg](https://wordpress.org/support/users/shellbeezy/)
 * (@shellbeezy)
 * Automattic Happiness Engineer
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644262)
 * Do you need to target the entire product listing or the specific products that
   match a category? If a product has multiple categories(even sub-categories), 
   all of them should be added as a class. In this case, the parent is ‘bicycles’
   and the child is ‘fixed gear’:
 * <li class= “product_cat-bicycles product_cat-fixed-gear”>
 *  Thread Starter [woober](https://wordpress.org/support/users/woober/)
 * (@woober)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644263)
 * Thanks for the reply Thomas.
 * I need all ‘fixed gear’ bicycles to have added a class in the category page, 
   as in your example.
    Not sure this matters: These bikes will also be shown elsewhere
   on the site, like at the frontpage under ‘Most bought’ etc. so its not only under
   the parent category.
 *  [Caleb Burks](https://wordpress.org/support/users/icaleb/)
 * (@icaleb)
 * Automattic Happiness Engineer
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644288)
 * Pretty sure this already exists: [http://cld.wthms.co/XRDn/5X5WEvPf](http://cld.wthms.co/XRDn/5X5WEvPf)
 * If you don’t see it for some reason, this should do the trick:
 *     ```
       function wc_ninja_add_category_html_class( $classes ) {
       	global $post;
       	$categories = get_the_terms( $post->ID, 'product_cat' );
   
       	if ( $categories ) {
       		foreach ( $categories as $category ) {
       			$classes[] = 'product-category-' . $category->slug;
       		}
       	}
   
       	return $classes;
       }
       add_filter( 'post_class', 'wc_ninja_add_category_html_class' );
       ```
   
 *  Thread Starter [woober](https://wordpress.org/support/users/woober/)
 * (@woober)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644289)
 * Thanks Caleb.
    You are absolutely right. Its already there, its just because 
   my these removes them. Thanks again, i will have to talk with them about it 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Category page class’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [woober](https://wordpress.org/support/users/woober/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/category-page-class/#post-7644289)
 * Status: resolved