WordPress文章页调用不带链接分类名,别名,分类ID
WordPress文章页调用所属分类名:
带链接:
<?php the_category(', ') ?>
不带链接:
<?php $category = get_the_category(); echo $category[0]->cat_name;?>
WordPress文章页调用所属分类ID:
<?php $category = get_the_category(); echo $category[0]->cat_ID;?>
WordPress文章页调用所属分类的别名(大写):
<?php $category = get_the_category(); echo $category[0]->slug;?>
WordPress文章页调用所属分类描述:
<?php $category = get_the_category(); echo $category[0]->category_description ;?>
WordPress文章页调用所属分类包涵的文章数量:
<?php $category = get_the_category(); echo $category[0]->category_count ;?>
WordPress文章页调用所属分类的父分类 ID :
<?php $category = get_the_category(); echo $category[0]->category_parent ;?>
WordPress文章页调用所属顶级分类下所有子分类名称和别名
第一步:获取文章所属的最顶级分类ID;将下面代码放到functions.php里面;
//获取顶级分类ID
function salong_category_top_parent_id ($current_cat_ID) {
while ($current_cat_ID) {
$cat = get_category($current_cat_ID);
$current_cat_ID = $cat->category_parent;
$catParent = $cat->cat_ID;
}
return $catParent;
}
第二步:在需要显示子分类的位置放上以下的代码。(含有调用子分类名称和子分类别名)
<?php foreach((get_the_category()) as $category){
$djcatid = salong_category_top_parent_id ($category->cat_ID);
}
$args=array(
'orderby' => 'name',
'child_of'=> $djcatid,
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "" ), $category->name ) . '" ' . '><em>' . $category->name.'</em>'.strtoupper($category->slug).'</a></li>';
}
?>