0

0

分享一个WordPress面包屑导航代码

藏色散人

藏色散人

发布时间:2021-05-06 10:13:33

|

3157人浏览过

|

来源于zmingcx

转载

下面由wordpress教程栏目给大家分享一个wordpress面包屑导航代码,希望对需要的朋友有所帮助!

转载分享一段WordPress面包屑导航代码,支持自定义帖子类型、自定义分类,但貌似在分类归档页面不能显示父子分类层级有点遗憾。

将代码添加到当前主题函数模板functions.php中:

/**
 * WordPress Breadcrumbs
 */
function tsh_wp_custom_breadcrumbs() {
 
    $separator              = '/';
    $breadcrumbs_id         = 'tsh_breadcrumbs';
    $breadcrumbs_class      = 'tsh_breadcrumbs';
    $home_title             = esc_html__('Home', 'your-domain');
 
    // Add here you custom post taxonomies
    $tsh_custom_taxonomy    = 'product_cat';
 
    global $post,$wp_query;
       
    // Hide from front page
    if ( !is_front_page() ) {
       
        echo '
    '; // Home echo '
  • ' . $home_title . '
  • '; echo '
  • ' . $separator . '
  • '; if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) { echo '
  • ' . post_type_archive_title('', false) . '
  • '; } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) { // For Custom post type $post_type = get_post_type(); // Custom post type name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo '
  • ' . $post_type_object->labels->name . '
  • '; echo '
  • ' . $separator . '
  • '; } $custom_tax_name = get_queried_object()->name; echo '
  • ' . $custom_tax_name . '
  • '; } else if ( is_single() ) { $post_type = get_post_type(); if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo '
  • ' . $post_type_object->labels->name . '
  • '; echo '
  • ' . $separator . '
  • '; } // Get post category $category = get_the_category(); if(!empty($category)) { // Last category post is in $last_category = $category[count($category) - 1]; // Parent any categories and create array $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),','); $cat_parents = explode(',',$get_cat_parents); // Loop through parent categories and store in variable $cat_display $cat_display = ''; foreach($cat_parents as $parents) { $cat_display .= '
  • '.$parents.'
  • '; $cat_display .= '
  • ' . $separator . '
  • '; } } $taxonomy_exists = taxonomy_exists($tsh_custom_taxonomy); if(empty($last_category) && !empty($tsh_custom_taxonomy) && $taxonomy_exists) { $taxonomy_terms = get_the_terms( $post->ID, $tsh_custom_taxonomy ); $cat_id = $taxonomy_terms[0]->term_id; $cat_nicename = $taxonomy_terms[0]->slug; $cat_link = get_term_link($taxonomy_terms[0]->term_id, $tsh_custom_taxonomy); $cat_name = $taxonomy_terms[0]->name; } // If the post is in a category if(!empty($last_category)) { echo $cat_display; echo '
  • ' . get_the_title() . '
  • '; // Post is in a custom taxonomy } else if(!empty($cat_id)) { echo '
  • ' . $cat_name . '
  • '; echo '
  • ' . $separator . '
  • '; echo '
  • ' . get_the_title() . '
  • '; } else { echo '
  • ' . get_the_title() . '
  • '; } } else if ( is_category() ) { // Category page echo '
  • ' . single_cat_title('', false) . '
  • '; } else if ( is_page() ) { // Standard page if( $post->post_parent ){ // Get parents $anc = get_post_ancestors( $post->ID ); // Get parents order $anc = array_reverse($anc); // Parent pages if ( !isset( $parents ) ) $parents = null; foreach ( $anc as $ancestor ) { $parents .= '
  • ' . get_the_title($ancestor) . '
  • '; $parents .= '
  • ' . $separator . '
  • '; } // Render parent pages echo $parents; // Active page echo '
  • ' . get_the_title() . '
  • '; } else { // Just display active page if not parents pages echo '
  • ' . get_the_title() . '
  • '; } } else if ( is_tag() ) { // Tag page // Tag information $term_id = get_query_var('tag_id'); $taxonomy = 'post_tag'; $args = 'include=' . $term_id; $terms = get_terms( $taxonomy, $args ); $get_term_id = $terms[0]->term_id; $get_term_slug = $terms[0]->slug; $get_term_name = $terms[0]->name; // Return tag name echo '
  • ' . $get_term_name . '
  • '; } elseif ( is_day() ) { // Day archive page // Year link echo '
  • ' . get_the_time('Y') . ' Archives
  • '; echo '
  • ' . $separator . '
  • '; // Month link echo '
  • ' . get_the_time('M') . ' Archives
  • '; echo '
  • ' . $separator . '
  • '; // Day display echo '
  • ' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives
  • '; } else if ( is_month() ) { // Month Archive // Year link echo '
  • ' . get_the_time('Y') . ' Archives
  • '; echo '
  • ' . $separator . '
  • '; // Month display echo '
  • ' . get_the_time('M') . ' Archives
  • '; } else if ( is_year() ) { // Display year archive echo '
  • ' . get_the_time('Y') . ' Archives
  • '; } else if ( is_author() ) { // Author archive // Get the author information global $author; $userdata = get_userdata( $author ); // Display author name echo '
  • ' . 'Author: ' . $userdata->display_name . '
  • '; } else if ( get_query_var('paged') ) { // Paginated archives echo '
  • '.__('Page') . ' ' . get_query_var('paged') . '
  • '; } else if ( is_search() ) { // Search results page echo '
  • Search results for: ' . get_search_query() . '
  • '; } elseif ( is_404() ) { // 404 page echo '
  • ' . 'Error 404' . '
  • '; } echo '
'; } }

将调用代码放到主题模板适当位置比如header.php中:

爱之谷成人用品商城整站 for ECshop
爱之谷成人用品商城整站 for ECshop

这是网上分享的第一个带整站数据包的爱之谷模板,希望大家支持开发者“ecshop模板堂”安装方法:1,解压rar包上传到网站根目录2,导入sql数据库文件,到你的数据库里,可以phpmyadmin等软件3,修改data里config.php里面的数据库 用户名 密码等信息 为你自己的数据库信息4,安装完毕之后的后台用户名密码为:后台地址:域名/admin用户名

下载

配套样式:

#tsh_breadcrumbs .separator{
    font-size:20px;
    color:#ccc;
    font-weight:100;
}
#tsh_breadcrumbs{
    overflow:hidden;
    text-align: center;
    list-style:none;
    margin:11px 0;
}
#tsh_breadcrumbs li{
    margin-right:14px;
    display:inline-block;
    vertical-align:middle;
}

相关文章

WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
wordpress seo
wordpress seo

WordPress网站SEO优化方法有:1、选择一个SEO友好的主题,具有清晰的代码结构,快速的加载速度和响应式设计;2、使用SEO插件,优化你的标题标签,元描述,关键字,XML站点地图等;3、优化你的内容,内容是SEO优化的核心;4、优化你的网站速度;5、创建友好的URL;6、使用内部链接;7、优化图像;8、使用社交媒体;9、定期更新你的网站;10、监控和分析你的网站等等。

420

2023.09.18

wordpress下载后怎么安装
wordpress下载后怎么安装

安装前准备:确保服务器满足要求、获取安装文件、创建数据库。上传 wordpress 文件。创建数据库和用户。运行安装程序:选择语言、输入数据库信息、网站标题和管理员信息。安装 wordpress。安装后配置:设置永久链接、安装主题、安装插件、创建内容。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

320

2024.04.15

全国统一发票查询平台入口合集
全国统一发票查询平台入口合集

本专题整合了全国统一发票查询入口地址合集,阅读专题下面的文章了解更多详细入口。

1

2026.02.03

短剧入口地址汇总
短剧入口地址汇总

本专题整合了短剧app推荐平台,阅读专题下面的文章了解更多详细入口。

3

2026.02.03

植物大战僵尸版本入口地址汇总
植物大战僵尸版本入口地址汇总

本专题整合了植物大战僵尸版本入口地址汇总,前往文章中寻找想要的答案。

5

2026.02.03

c语言中/相关合集
c语言中/相关合集

本专题整合了c语言中/的用法、含义解释。阅读专题下面的文章了解更多详细内容。

2

2026.02.03

漫蛙漫画网页版入口与正版在线阅读 漫蛙MANWA官网访问专题
漫蛙漫画网页版入口与正版在线阅读 漫蛙MANWA官网访问专题

本专题围绕漫蛙漫画(Manwa / Manwa2)官网网页版入口进行整理,涵盖漫蛙漫画官方主页访问方式、网页版在线阅读入口、台版正版漫画浏览说明及基础使用指引,帮助用户快速进入漫蛙漫画官网,稳定在线阅读正版漫画内容,避免误入非官方页面。

3

2026.02.03

Yandex官网入口与俄罗斯搜索引擎访问指南 Yandex中文登录与网页版入口
Yandex官网入口与俄罗斯搜索引擎访问指南 Yandex中文登录与网页版入口

本专题汇总了俄罗斯知名搜索引擎 Yandex 的官网入口、免登录访问地址、中文登录方法与网页版使用指南,帮助用户稳定访问 Yandex 官网,并提供一站式入口汇总。无论是登录入口还是在线搜索,用户都能快速获取最新稳定的访问链接与使用指南。

30

2026.02.03

Java 设计模式与重构实践
Java 设计模式与重构实践

本专题专注讲解 Java 中常用的设计模式,包括单例模式、工厂模式、观察者模式、策略模式等,并结合代码重构实践,帮助学习者掌握 如何运用设计模式优化代码结构,提高代码的可读性、可维护性和扩展性。通过具体示例,展示设计模式如何解决实际开发中的复杂问题。

2

2026.02.03

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
第二十三期_前端开发
第二十三期_前端开发

共98课时 | 7.6万人学习

WordPress视频教程
WordPress视频教程

共23课时 | 9.7万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号