我们在做WordPress企业模板中常常需要在文章页调用当前分类的名称和链接。
常用的调用代码:
文章页调用分类名称
- <?php foreach((get_the_category()) as $category){echo $category->cat_name;} ?>
调用分类别名
- <?php $cat = get_category($cid);echo $cat->slug;?>
文章页调用分类链接
- <?php
- $category = get_the_category();
- if($category[0]){
- echo ''.get_category_link($category[0]->term_id ).'';
- }
- ?>
- 我的微信
- 有问题可随时与我联系
-
- 微信小程序
- 随时随地查看文章
-