<?php echo get_the_term_list( $post->ID, \'people\', \'People: \', \' \', \'\' ); ?>
返回如下内容:People: <a href="person1">Person1</a>, <a href="person2">Person2</a>, ...
如果没有以下链接,我如何使其返回相同的内容:People: Person1, Person2
<?php echo get_the_term_list( $post->ID, \'people\', \'People: \', \' \', \'\' ); ?>
返回如下内容:People: <a href="person1">Person1</a>, <a href="person2">Person2</a>, ...
如果没有以下链接,我如何使其返回相同的内容:People: Person1, Person2
手动编写列表可能更容易,例如:
<?php
$terms = wp_get_post_tags( $post->ID );
//For custom taxonomy use this line below
//$terms = wp_get_object_terms( $post->ID, \'people\' );
foreach( $terms as $term )
$term_names[] = $term->name;
echo implode( \', \', $term_names );
或者,您也可以使用
<?php
echo strip_tags (
get_the_term_list( get_the_ID(), \'tax_name\', "Text Before Value ",", " )
);
?>
我找到了另一种更直接回答我问题的方法:
<?php $terms_as_text = get_the_term_list( $post->ID,\'people\', \'People: \', \', \');
if (!empty($terms_as_text)) echo \'<p>\', strip_tags($terms_as_text) ,\'</p>\'; ?>
信用证:CSS Tricks如果要将术语显示为HTML列表,则使用strip\\u tags()可能会变得复杂。这儿,有件东西给你$将raw设置为true(或任何非空的内容)只会创建一个带有您选择的$分隔符的内联列表,如果不是,它将生成一个没有链接的HTML列表。如果希望列表具有样式化的标题,请将$titletag设置为H1或H2。如果不需要标题,只需将$title留空即可。
function show_tax($taxname, $title, $title_tag, $raw, $separator){
$terms = get_the_terms($post->ID, $taxname);
$out = \'\';
if (!empty($title)){
if(empty($title_tag)){
$title_tag = \'span\';
}
$out .= \'<\'.$title_tag.\'>\'.$title.\'</\'.$title_tag.\'>\';
}
if (!empty($raw)){
$out = implode($separator, $terms);
}
else{
$out .= \'<ul>\';
foreach ( $terms as $term ){
$out .=\'<li>\'.$term->name.\'</li> \';
}
$out .= \'</ul>\';
}
return $out;
}
使用示例:echo show_tax(\'people\', \'PEOPLE\', \'h3\', \'\', \'\'); // An html list with PEOPLE as title
echo show_tax(\'people\', \'PEOPLE:\', \'\', true, \',\'); // An inline list with PEOPLE: as before text
我希望通过多站点博客网络实现标准类别术语。目标是:在一个博客(或根博客)上创建一个类别,并在所有博客上创建该类别。每个博客都有自己的类别URL,例如,将测试名为“苹果”的类别。实例com/类别/苹果和其他测试。实例com/categories/apples-只在相应的博客上列出这些帖子我在代码中看到了global\\u术语的概念-我不确定这是否相关,因为我找不到很多关于这方面的文档,也不知道它是否在3.0中被弃用。x、 如果这就是我要找的,有人能举个例子吗?谢谢丹