获取wordpress 当前栏目名,当前栏目的分类名

wordpress在设计主题和做模板时经常会用到调用当前分类栏目名称,常见的有当前栏目页、文章页,详情代码如下:

1.分类名称与链接

<?php the_category(); ?>

2.分类页面调用当前分类名称,要在分类页得到分类页面的栏目名称,需要用

<?php single_cat_title(); ?>

3.文章页调用当前文章所属分类名称

代码1
<?php
 foreach((get_the_category())&nbsp;as&nbsp;$category)
 {echo&nbsp;$category->cat_name;}
 ?>

代码2
<?php
 $category&nbsp;= get_the_category();
 echo&nbsp;$category[0]->cat_name;
 ?>

代码3
<?php
 &nbsp;$thiscat&nbsp;
 = get_category($cat);&nbsp;echo&nbsp;
 $thiscat&nbsp;->name;
 ?>

4.调用分类名称别名

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

小 虾

哦也,我是小虾

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

anti fatigue mats