• Resolved juhosallinen

    (@juhosallinen)


    Hi,

    Is it possible to apply CSS classes based on testimonial categories? I have 3 separate product groups with their own color themes and I’d like to associate the testimonials with them.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • anonymized-13171256

    (@anonymized-13171256)

    Great idea!

    Add this to your theme’s functions.php or create an mu-plugin.

    /**
     * Add category to testimonial CSS classes.
     *
     * For Strong Testimonials.
     */
    function my_testimonial_class( $classes, $args ) {
    	global $post;
    
    	$class_list = explode( ' ', $classes );
    
    	$categories = wp_get_object_terms( $post->ID, 'wpm-testimonial-category' );
    
    	if ( ! empty( $categories) && ! is_wp_error( $categories ) ) {
    		foreach ( $categories as $category ) {
    
    			// To add the ID:
    			$class_list[] = 'category-' . $category->term_id;
    
    			// To add the slug:
    			$class_list[] = 'category-' . $category->slug;
    
    		}
    	}
    
    	$classes = implode( ' ', array_unique( $class_list ) );
    
    	return $classes;
    }
    add_filter( 'wpmtst_post_class', 'my_testimonial_class', 10, 2 );

    Example CSS:

    .strong-view .testimonial.category-1 {
      border: 1px solid red;
    }

    or

    .strong-view .testimonial.category-my-product {
      border: 1px solid red;
    }

    You may need to increase the specificity by adding the template name:

    .strong-view.default .testimonial.category-2 {
      border: 1px solid red;
    }
    Thread Starter juhosallinen

    (@juhosallinen)

    Thank you, this is just what I needed! If you ever get around to it, adding this to the UI of the plugin would probably be well received!

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

The topic ‘Custom CSS for categories?’ is closed to new replies.