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

wordpress子分类调用父分类名称和链接的3种方法

专为导航而生,在wordpress模板制作过程中常常会在做breadcrumbs导航时会用到,子分类调用父分类的名称和链接,下面这段简洁的代码,可以完美解决这个问题。

<?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?>

下面这种方法也可以,不过代码不够简洁。

<?php
if ( is_category() ) {// Get the current category term id.$query_obj = get_queried_object();$term_id   = $query_obj->term_id;echo get_term_parents_list( $term_id, 'category' );
}
?>

第三种方法,调用分类目录名称和链接,作为导航。

<?php
if ( ( is_tax() || is_category() || is_tag() ) ) {$trail     = '';$home      = '/<a href="' . get_home_url() . '">Home</a>';$query_obj = get_queried_object();$term_id   = $query_obj->term_id;$taxonomy  = get_taxonomy( $query_obj->taxonomy );if ( $term_id && $taxonomy ) {// Add taxonomy label name to the trail.// $trail .=  '/' . $taxonomy->labels->menu_name;// Add term parents to the trail.$trail .= '/' . get_term_parents_list( $term_id, $taxonomy->name, array( 'inclusive' => false ) );}// Print trail and add current term name at the end.echo '<p class="breadcrumb-trail">' . $home . $trail . $query_obj->name . '</p>';
}
?>

 原文

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

http://www.lryc.cn/news/544412.html

相关文章:

  • Prometheus + Grafana 监控
  • 初学STM32之简单认识IO口配置(学习笔记)
  • springboot2.7.18升级springboot3.3.0遇到的坑
  • gtest 和 gmock讲解
  • GC垃圾回收介绍及GC算法详解
  • 2020 年英语(一)考研真题 笔记(更新中)
  • 【springboot】Spring 官方抛弃了 Java 8!新idea如何创建java8项目
  • playbin之autoplug_factories源码剖析
  • 正浩创新内推:校招、社招EcoFlow社招内推码: FRQU1CY
  • 一文了解:部署 Deepseek 各版本的硬件要求
  • 有没有什么免费的AI工具可以帮忙做简单的ppt?
  • python绘图之灰度图
  • 华为 VRP 系统简介配置SSH,TELNET远程登录
  • 1.14 重叠因子:TRIMA三角移动平均线(Triangular Moving Average, TRIMA)概念与Python实战
  • 【tplink】校园网接路由器如何单独登录自己的账号,wan-lan和lan-lan区别
  • PC 端连接安卓手机恢复各类数据:安装、操作步骤与实用指南
  • 【折线图 Line】——1
  • SpringBoot 整合mongoDB并自定义连接池,实现多数据源配置
  • TCP/IP的分层结构、各层的典型协议,以及与ISO七层模型的差别
  • FreeRTOS-中断管理
  • ShenNiusModularity项目源码学习(15:ShenNius.Admin.API项目分析)
  • Express + MongoDB 实现文件上传
  • 计算机毕业设计SpringBoot+Vue.js作业管理系统(源码+文档+PPT+讲解)
  • Odoo免费开源CRM技术实战:从商机线索关联转化为售后工单的应用
  • 2025年如何实现安卓、iOS、鸿蒙跨平台开发
  • 萌新学 Python 之 os 模块
  • IPoIB源码深度解析:如何基于TCP/IP协议栈实现高性能InfiniBand通信
  • 本地部署阿里万象2.1文生视频模型(Wan2.1-T2V)完全指南
  • information_schema.processlist 表详解
  • P8623 [蓝桥杯 2015 省 B] 移动距离