Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @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/

    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

    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/

    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

    (@majklas)

    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>

    Hi @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?

    Hi @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.