is there a way to modify the the_content() function? I would like to add a css class when it display a custom taxonomy negative and positive taxonomy.
Example:
<p class="positive">this is a content for the positive taxonomy</p>
<p class="positive">this is a content for the positive taxonomy</p>
<p class="negative">this is a content for the negative taxonomy</p>
I would like to apply it in the author.php code:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('No posts by this author.'); ?></p>
<?php endif; ?>
with the function.php :
add_action( 'pre_get_posts', function ( $q ) {
if( !is_admin() && $q->is_main_query() && $q->is_author() ) {
$q->set( 'posts_per_page', 100 );
$q->set( 'post_type', 'custom_feedback' );
}
});
PS: I am using custom post type here with custom taxonomy with two category positive and negative.
You can use
has_term()
to test whether or not a post has a certain term. Alternatvely, you can useget_the_terms
to get the terms attached to a post and use the term slug as value in your css class. This is a bit unreliable if a post has more than one term attached to itSOLUTION 1
SOLUTION 2
USAGE
You can now use your CSS selectors to target your content