我有一个页面,我所有的可湿性粉剂的职位显示。类别的职位显示罚款,但当我试图也显示分类,它不工作。
这是可行的:
<span><i class="fa fa-list"></i><?php $categories = get_the_category();
$separator = ", ";
$output = '';
if($categories){
if($link_on_cat == "yes"){
foreach($categories as $category){
$output .= '<a href="' .get_category_link($category->term_id) .'">' . $category->cat_name . '</a>' . $separator;
}
} else {
foreach($categories as $category){
$output .= $category->cat_name . $separator;
}
}
echo trim($output, $separator);
} ?></span>
这是行不通的:
<span><i class="fa fa-list"></i><?php $categories = get_the_category();
$separator = ", ";
$output = '';
global $post, $post_id;
$post_type = $post->post_type;
$taxonomies = get_object_taxonomies($post_type);
if($categories){
if($link_on_cat == "yes"){
foreach($categories as $category){
$output .= '<a href="' .get_category_link($category->term_id) .'">' . $category->cat_name . '</a>' . $separator;
}
foreach ($taxonomies as $taxonomy) { $out .= "<li>".$taxonomy.": "; $terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) ) {
foreach ( $terms as $term )
$out .= '<a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a> ';
} }
} else {
foreach($categories as $category){
$output .= $category->cat_name . $separator;
}
}
echo trim($output, $separator);
} ?></span>
我当然是做错了,但是错了什么?
1条答案
按热度按时间46scxncf1#
试试这个代码