Wordpress,通过自定义链接回显slug术语列表

Wordpress,通过自定义链接回显slug术语列表,wordpress,loops,slug,Wordpress,Loops,Slug,我试图通过自定义链接获得一个术语列表(使用CPT UI),其中slug是自定义链接的最后一部分 例如: 客户:条款1、条款2、条款3 其中每个术语都是一个链接,如: example.com/#term1 example.com/#term2 example.com/#term3 因此,我有相同的自定义链接结构,但只有最后的slug发生了变化: $servizio = get_the_terms($post->ID, 'servizio'); $servizio = array_value

我试图通过自定义链接获得一个术语列表(使用CPT UI),其中slug是自定义链接的最后一部分

例如: 客户:条款1、条款2、条款3

其中每个术语都是一个链接,如:

example.com/#term1
example.com/#term2
example.com/#term3
因此,我有相同的自定义链接结构,但只有最后的slug发生了变化:

$servizio = get_the_terms($post->ID, 'servizio');
$servizio = array_values($servizio);
    for($cat_count=0; $cat_count<count($servizio); $cat_count++) {
        echo $servizio[$cat_count]-> slug;
        if ($cat_count<count($servizio)-1){
            echo ', ';
        }
    }
$servizio=获取术语($post->ID,'servizio');
$servizio=数组_值($servizio);
对于($cat\u count=0;$cat\u count slug;

如果($cat_count改为使用
foreach
循环,则在术语方面进行迭代要容易得多

$categories = get_the_terms(get_the_ID(), 'servizio');
$categories_output = [];

if ($categories) { // Prevent the error #Invalid argument supplied for foreach()# incase the post has no category
    foreach ($categories as $category) {
        $categories_output[] = '<a href='. get_bloginfo('url') . '/#' . $category->slug .'>'. $category->name .'</a>';
    }
}

if ($categories_output) {
    echo implode(', ', $categories_output);
}
$categories=获取术语(获取ID(),'servizio');
$categories_输出=[];
如果($categories){//防止错误#为foreach()提供的参数无效#如果post没有类别
foreach($categories作为$category){
$categories_输出[]='';
}
}
如果($U输出){
回波内爆(“,”,$U输出);
}