我有以下代码:
<?php echo get_the_term_list($post->ID, 'themes', '', '', ''); ?>
哪个给我以下输出:
<a href="https://www.domain.test/themes/dark/" rel="tag">Dark</a>
<a href="https://www.domain.test/themes/white/" rel="tag">White</a>
问题是...如何向输出添加类?我希望结果是类似...
<a href="https://www.domain.test/themes/dark/" class="custom" rel="tag">Dark</a>
<a href="https://www.domain.test/themes/white/" class="custom" rel="tag">White</a>
谢谢!
答案 0 :(得分:0)
我认为您需要使用自定义循环来添加类。
<?php
$themes = get_the_terms( $post->ID, 'themes');
if ($themes && ! is_wp_error($themes)): ?>
<?php foreach($themes as $theme): ?>
<!-- The slug is the URL of taxonomy, defined at the time of registration taxonomy within 'rewrite'.-->
<a href="<?php echo get_term_link( $theme->slug, 'themes'); ?>" rel="tag" class="custom <?php echo $theme->slug; ?>"><?php echo $theme->name; ?></a>
<?php endforeach; ?>
<?php endif; ?>