Add CSS to term name

Support MB Views Add CSS to term nameResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34403
    philippe@studiocassette.com[email protected]
    Participant

    Hello,
    I would like to add CSS class to my taxonomy terms.
    I used this code to display my taxonomies :

    {{ mb.get_the_term_list( post.ID, 'thematique', '', ', ' ) }}

    it works perfectly but how to customize the apparence of each term.
    I would like to add a CSS class like this :

    .thema {background:#007e4e ; padding: 5px ; border-radius:10px }

    Thx for your help.

    Olivier

    #34431
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use the WordPress function get_the_terms() to get list of terms without the HTML included. Then use a for loop to iterate through array of terms and add the term slug/name to the custom <div> tag. For example:

    {% set term_list = mb.get_the_terms( post.ID, 'thematique' ) %}
    
    {% for term in term_list %}
        <div class="term-item {{ term.slug }}">
            {{ term.name }}
        </div>
    {% endfor %}

    Refer to the documentation https://developer.wordpress.org/reference/functions/get_the_terms/

    #34434
    philippe@studiocassette.com[email protected]
    Participant

    Ok thx a lot but how to get each term with the link and a CSS class on each term ?

    #34436
    philippe@studiocassette.com[email protected]
    Participant

    I solved my problem , thx a lot 😉

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.