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; }
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.