📜  在单篇文章中获取分类名称 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:36.841000             🧑  作者: Mango

代码示例1
// RETRIVE TERM SLUG ( for single.php or template-part )

$terms = get_the_terms( $post->ID, 'your-taxonomy' );
if ( !empty( $terms ) ){
    // get the first term
    $term = array_shift( $terms );
    echo $term->slug;
}