wordpress文章页调用当前分类名称和链接的代码

2021年10月25日11:55:21 发表评论
广告也精彩

我们在做WordPress企业模板中常常需要在文章页调用当前分类的名称和链接。

常用的调用代码:

文章页调用分类名称

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

调用分类别名

  1. <?php $cat = get_category($cid);echo $cat->slug;?>

文章页调用分类链接

  1. <?php
  2. $category = get_the_category();
  3. if($category[0]){
  4. echo ''.get_category_link($category[0]->term_id ).'';
  5. }
  6. ?>

wordpress文章页调用当前分类名称和链接的代码



微信扫描下方的二维码阅读本文

ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容