在我的WordPress分类部分,我有一个Food
主要类别,以及其他子类别(“汉堡、意大利面食、主食等”)。在帖子页面中,我只想显示帖子中填写的子类别。
我想显示所选的唯一子类别。如果职位在Food > hamburger
和Food > main
, 我只想在帖子页面上显示这两个类别,而不是所有类别。我尝试使用此代码,但它将显示所有类别:
$categories = get_categories( array(
\'taxonomy\' => \'category\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'include\' => \'all\',
\'exclude\' => \'\',
\'exclude_tree\' => \'all\',
\'number\' => false,
\'fields\' => \'all\',
\'name\' => \'\',
\'slug\' => \'\',
\'hierarchical\' => true,
\'search\' => \'\',
\'name__like\' => \'\',
\'description__like\' => \'\',
\'pad_counts\' => false,
\'get\' => \'\',
\'child_of\' => false,
\'childless\' => false,
\'cache_domain\' => \'core\',
\'update_term_meta_cache\' => true,
\'meta_query\' => \'\',
\'meta_key\' => array(),
\'meta_value\'=> \'\'
));
foreach ( $categories as $category ) {
printf( \'<a href="%1$s">%2$s</a><br />\',
esc_url( get_category_link( $category->term_id ) ),
esc_html( $category->name )
);
}