我甚至很难为这个想出一个标题。
如果我正在编辑监管者旧博客文章(content.php)的代码,并添加
<?php the_category(', ') ?>
我得到了帖子所属的所有类别的可单击列表。
我有一个称为研究的自定义帖子类型,与之相关的一个自定义分类法称为主题。我正在编辑content-research.php,我只希望主题在查看研究文章时以相同的方式显示。
我试过了
<?php the_topic(', ') ?>
那是一个彻底的失败。
因此,我希望有一个简单的解决方案,因为我也想为此帖子类型添加一些其他分类法。
the_category()
如您在核心文件https://core.trac.wordpress.org/browser/tags/4.9.2/src/wp-includes/category-template.php行中所见,此函数仅从“类别”分类法中搜索术语75
您可以编写自己的函数,也可以使用以下代码段:
$terms = get_the_terms( $post->ID , 'taxonomyname' );
foreach ( $terms as $term ) {
echo '<a href="'.get_term_link($term->term_id).'">'.$term->name</a>.' ';
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句