当前位置: 首页 > news >正文

wordpress自定the_category的输出结构

通过WordPress的过滤器the_category来自定义输出内容。方法很简单,但是很实用。以下是一个示例代码:

function custom_the_category($thelist, $separator = '', $parents = '') {
    // 获取当前文章的所有分类
    $categories = get_the_category();

    if (empty($categories)) {
        return $thelist;
    }

    $thelist = '';
    foreach ($categories as $category) {
        $cat_name = esc_html($category->name);
        $cat_link = esc_url(get_category_link($category->term_id));

        // 自定义每个分类的HTML结构
        $thelist .= '<div class="custom-category-item">';
        $thelist .= '<a href="' . $cat_link . '" class="custom-category-link">';
        $thelist .= '<span class="custom-category-name">' . $cat_name . '</span>';
        $thelist .= '</a>';
        $thelist .= '</div>';
    }

    return $thelist;
}
add_filter('the_category', 'custom_the_category', 10, 3);

然后在模板文件中,你可以像平常一样调用the_category()函数:

<?php the_category(', '); ?>

 原文

http://www.chudafu.com/jianzhan/6932.html

相关文章:

  • 【C++】中的赋值初始化和直接初始化的区别
  • SSM架构 +java后台 实现rtsp流转hls流,在前端html上实现视频播放
  • 低代码开发直聘管理系统
  • Electron应用中获取设备唯一ID和系统信息
  • 【游戏】【客户端性能测试】
  • 【数据库系统概论】事务
  • vue 封装流动的线组件(支持实线, 虚线, 变色, 流动)
  • 企业AI数据安全白皮书:深寻模型会话保护与安当TDE实战
  • 初识CMDB:数据质量的管理
  • 责任链模式:优雅处理复杂流程的设计艺术
  • 扩展------项目中集成阿里云短信服务
  • Android Studio 一直 Loading devices
  • C++:面向对象编程(续)
  • DeepSeek DeepEP学习(二)normal notify dispatch
  • 【开源宝藏】Spring Trace 一种轻量级的日志追踪新方式
  • 第三次CCF-CSP认证(含C++源码)
  • Redis数据结构深度解析:从String到Stream的奇幻之旅(一)
  • Clion快捷键、修改字体
  • 深度学习系列78:使用langchain的api进行RAG
  • 介绍exadata中的smart Scan技术
  • 如何制作网站页面/怎样优化标题关键词
  • 网站建设需要了解的/千锋教育培训机构可靠吗
  • 展示型网站/个人网站网页首页
  • 网站建设中销售人员会问客户的问题/怎样做网站的优化、排名
  • 做网站的费用 优帮云/重庆seo教程搜索引擎优化
  • 兰溪优秀高端网站设计地址/搜索引擎seo是什么