Support

Account

Home Forums Front-end Issues Loop Category with custom text field and add current-cat class Reply To: Loop Category with custom text field and add current-cat class

  • I would add the class to the container, but wherever you add it the code would be similar.

    
    <?php
    $taxonomy = 'category';
    $queried_term = get_term_by( 'slug', get_query_var($taxonomy), 0 );
    $terms = get_terms($taxonomy);
    $terms = get_terms(
    array(
    'parent' => 0
    )
    );
    $term = get_term('category' );
    if ($terms) {
                                        
    foreach($terms as $term) {
                                    
    $icon = get_field('icon', $taxonomy . '_' . $term->term_id);
    
    $cat_class = 'category-'.$term->slug;    
                                                            
    if( get_field('icon', $taxonomy . '_' . $term->term_id)):
    ?>
    <div class="item category-carousel <?php echo $cat_class; ?>">
    <a href="<?php echo get_term_link($term->slug, $taxonomy) ?>" title="Consulta i lavori nella Categoria: <?php echo $term->name ?>">
    <span class="cat-icon"><?php echo $icon; ?></span>
    <span class="cat-name"><?php echo $term->name ?></span>
    </a>   
    </div><!--/.item-->    
    <?php  endif; }
    }
    ?>