我有以下代码:
<?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>
提前致谢!
最佳答案
我认为您必须使用自定义循环来添加类。
<?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; ?>