Add all shop categories classes to body
-
Hope someone can help here.
I found this code on here already:
/** * Custom class for the 'body_class()' function * Add product category only on single view */ function isa_body_classes($classes) { // only add body class when viewing single product if(wpsc_is_single_product()) { //get cat of product function isa_get_cat() { global $wp_query, $wpsc_query; $query_data = Array(); $isa_post_id = wpsc_the_product_id(); $categories = wp_get_object_terms( $isa_post_id , 'wpsc_product_category' ); //if product is associated w more than one category if(count($categories) > 1 && isset($wpsc_query->query_vars['wpsc_product_category'])) $query_data['category'] = $wpsc_query->query_vars['wpsc_product_category']; elseif(count($categories) > 0) $query_data['category'] = $categories[0]->slug; return $query_data['category']; } //ends get cat, now echo the cat as class below $classes[] = isa_get_cat(); }; return array_unique($classes); }; add_filter('body_class','isa_body_classes');
It does want I wanted at the time, however, I now wish to add all shop categories to the body class. The above code pulled out one, for example ‘cushions’, I have say one product in a category called ‘cushion’, ‘collection1’.
I’m using GetShopped, does anyone know the answer?
Regards.
[Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]
- The topic ‘Add all shop categories classes to body’ is closed to new replies.