阿里云服务器

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

常用的调用代码:<?php the_category(', ') ?>

调用出来的样式:

<a href="https://www.518theme.com/seocourse/" title="seo教程" target="_blank">seo教程</a>

下面给大家介绍一下分别调用分类名称和链接的方法:

文章页调用分类名称

<?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 ).'';
}
?>

分类连接.png

相关阅读:
  • wordpress搜索功能优化:只搜索指定分类的文章
  • WordPress调用指定分类子分类的数据和文章列表
  • WordPress无用数据清理插件:WPDBSpringClear
  • 设置WordPress一级分类不显示二级分类文章的方法
  • wordpress下拉菜单设置方法
  • WordPress页面添加自定义摘要功能
  • wordpress特色图片地址调用方法
  • wordpress 调用分类列表 不同的列表样式
  • WordPress分别循环输出多个分类的最新文章