我正在尝试解决一个问题,需要帮助:)首先,我有一个自定义网格,显示自定义分类法中的术语和图像。这是我当前使用的代码:
<?php
$terms = get_terms( \'industrygroups\' , \'hide_empty=false\' );
echo \'<div class="row">\';
foreach ( $terms as $term ) {
    // The $term is an object, so we don\'t need to specify the $taxonomy.
    $term_link = get_term_link( $term );
    // If there was an error, continue to the next term.
    if ( is_wp_error( $term_link ) ) {
        continue;
    }
    // We successfully got a link. Print it out.
    echo \'<div class="col-lg-3"><a href="\' . esc_url( $term_link ) . \'">\' . $term->name . \'</a></div>\';
}
echo \'</div>\';
?>
 我现在想要完成的是使用我的分类术语中的自定义字段(通过
ACF. 该字段是一个下拉列表,显示不同的级别1-5。
我希望每个选定的级别在前端网格中显示的税项周围输出不同的颜色边框/背景
现在,我一直在努力this tutorial 它解决了如何通过帖子实现这一点,但是我很难将这一思路转移到分类术语上。我希望得到一些建议。非常感谢。
 
                SO网友:Sven
                您可以使用每个术语的slug作为类名(并通过CSS进行样式设置)
<?php
echo \'<div class="col-lg-3 \' . $term->slug . \'">\'; // $term->slug is the class name
echo \'<a href="\' . esc_url( $term_link ) . \'">\' . $term->name . \'</a>\';
echo \'</div>\';
?>
 如果要使用动态术语和颜色,我建议
Mark Posts Plugin; 可以在管理区域中管理术语/颜色,也可以在前端显示术语/颜色,如您所见
here:
<?php
/*
 * Display terms & colors of a post
 */
$post_markers = wp_get_post_terms( $post->ID, \'marker\' );
echo \'<ul>\';
foreach ( $post_markers as $post_marker ) :
  echo \'<li>\';
  echo __(\'Marker\', \'textdomain\') . \': \' . $post_marker->name  . \'<br />\';
  echo __(\'Color\', \'textdomain\') . \': \' . $post_marker->description . \'<br />\';
  echo \'</li>\';
endforeach;
echo \'</ul>\';
?>