Title: active category
Last modified: August 21, 2016

---

# active category

 *  Resolved [Majklas](https://wordpress.org/support/users/majklas/)
 * (@majklas)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/active-category/)
 * I know in wordpress it is available to determine which menu item or category 
   is active when viewing post. This is not available in marketpress with it’s custom
   posts. How can I get some css class next to a ancestor menu item which product
   I am viewving?
 * [https://wordpress.org/plugins/wordpress-ecommerce/](https://wordpress.org/plugins/wordpress-ecommerce/)

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

 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/active-category/#post-4876480)
 * Hi [@majklas](https://wordpress.org/support/users/majklas/),
 * Greetings and thanks for your question! Currently, it’s possible to create custom
   templates for MarketPress’ Product post type like detailed here:
    [http://premium.wpmudev.org/blog/the-easy-guide-to-theming-marketpress/](http://premium.wpmudev.org/blog/the-easy-guide-to-theming-marketpress/)
 * You could thus make changes there, adding category classes and such.
 * However, I think this may be easier done with a filter like so:
    [https://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters](https://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters)
 * Given that, you could try using this:
 *     ```
       <?php
       // add MarketPress product categories to post class
       function mp_post_class_categories($classes) {
       	global $post;
           $terms = get_the_terms( $post->ID, 'product_category' );
           foreach( $terms as $term)
               $classes[] = $term->name;
               return $classes;
       }
       add_filter('post_class', 'mp_post_class_categories');
       ?>
       ```
   
 * You can add that to your theme’s functions.php or through Code Snippets:
    [http://wordpress.org/plugins/code-snippets/](http://wordpress.org/plugins/code-snippets/)
 * And given that, you should then be able to style posts based on the categories
   available through the post div via CSS.
 * How would that work for you?
 * Cheers,
    David
 *  Thread Starter [Majklas](https://wordpress.org/support/users/majklas/)
 * (@majklas)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/active-category/#post-4876513)
 * Hi, thank You for this tip, but I cannot get a class to style.. I think You posted
   option to get a class for a pot, not menu item.
    My menu is:
 *     ```
       <ul id="mp_category_list">
       <li class="cat-item cat-item-8"> ...
       <li class="cat-item cat-item-18">
       <a title="test" href="http://project/store/products/category/xxx/">New product category</a>
       </li>
       </ul>
       ```
   
 * when I’m in a product of this “New product category” it doesn’t get any classes
   on LI element. I can see “current-cat” when I’m viewing category product list:
 *     ```
       <ul id="mp_category_list">
       <li class="cat-item cat-item-8"> ...
       <li class="cat-item cat-item-18 <strong>current-cat</strong>">
       <a title="test" href="http://project/store/products/category/xxx/">New product category</a>
       </li>
       </ul>
       ```
   
 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/active-category/#post-4876522)
 * Hi [@majklas](https://wordpress.org/support/users/majklas/),
 * Thanks for your reply. Here’s an adjusted version of the above code that will
   add the class to the body tag as well:
 *     ```
       <?php
       function mp_post_class_categories($classes) {
           global $post;
           $terms = get_the_terms( $post->ID, 'product_category' );
           foreach( $terms as $term)
               $classes[] = $term->name;
           return $classes;
       }
       add_filter('post_class', 'mp_post_class_categories');
       add_filter('body_class', 'mp_post_class_categories');
       ?>
       ```
   
 * Given that, you can target the category like so:
 *     ```
       body.yourcategory ul.mp_category_list li {
       }
       ```
   
 * Does that help?
 *  Plugin Author [WPMU DEV – Your All-in-One WordPress Platform](https://wordpress.org/support/users/wpmudev/)
 * (@wpmudev)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/active-category/#post-4876616)
 * Hi [@majklas](https://wordpress.org/support/users/majklas/),
 * Just wanted to check back on this. It’s marked as resolved but we’d love to assist
   if you have any questions or concerns. Just let us know.
 * We’re happy to help!

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

The topic ‘active category’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wordpress-ecommerce_f7d96b.svg)
 * [MarketPress - WordPress eCommerce](https://wordpress.org/plugins/wordpress-ecommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-ecommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-ecommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-ecommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-ecommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-ecommerce/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [WPMU DEV – Your All-in-One WordPress Platform](https://wordpress.org/support/users/wpmudev/)
 * Last activity: [11 years, 12 months ago](https://wordpress.org/support/topic/active-category/#post-4876616)
 * Status: resolved