wordpress获取当前分类名称或别名

wordpress yekong 2059℃

<?php the_category(); ?>

来调用分类名称与连接的


<?php single_cat_title(); ?>

分类页面调用当前分类名称

1.
<?php
foreach((get_the_category()) as $category)
{
echo $category->cat_name;
}
?>

2.
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>

3.
<?php $thiscat = get_category($cat); echo $thiscat ->name;?>

在在文章页想调用出当前文章所属分类的名称


if(is_category()) {
$cat = get_query_var('cat');
$yourcat = get_category($cat);
echo "该分类别名为" . $yourcat->slug;
}

获取分类别名的办法

喜欢 (1)