介绍
小编给大家分享一下WordPress免插件如何实现面包屑导航的方法,希望大家阅读完这篇文章后大所收获、下面让我们一起去探讨吧!
1,将下面的代码添加到主题的<>强功能。php 强>:
/* * * WordPress添加面包屑导航 * http://www.511yj.com/wordpress-add-breadcrumb.html */函数cmp_breadcrumbs () { 分隔符=& # 39;美元,raquo; & # 39;;//分隔符 $=& # 39;前& lt;跨类=癱urrent"在& # 39;;//在当前链接前插入 $=& # 39;后& lt;/span> & # 39;;//在当前链接后插入 如果(! is_home (),,! is_front_page () | | is_paged ()) { 回声& # 39;& lt; div itemscope itemtype=癶ttp://schema.org/WebPage"id=癱rumbs"祝辞& # 39;。__(& # 39;当前位置:& # 39;& # 39;cmp # 39;); 全球美元的帖子; $求租者=home_url (); 回声& # 39;& lt; itemprop=癰readcrumb"href=https://www.yisu.com/zixun/薄G笞庹呙涝!皉el="外部nofollow”>”。__(“无作为',' cmp ')。>。美元的分隔符。' '; 如果(is_category()){//分类存档 全球wp_query美元; $ cat_obj=$ wp_query -> get_queried_object (); 美元thisCat=$ cat_obj -> term_id; (thisCat=get_category美元thisCat); $ parentCat=get_category ($ thisCat ->父); 如果($ thisCat ->父!=0){ 美元cat_code=get_category_parents (parentCat美元,真的,' '。美元的分隔符。' '); echo $ cat_code=(' <', ' <大小写不敏感itemprop=懊姘肌?cat_code美元); } echo $。”。single_cat_title(假)。”。之后美元; }elseif (is_day()){//天存档 itemprop回声”<=懊姘肌県ref="的。get_year_link (get_the_time (Y))。“rel="外部nofollow”rel="外部nofollow”>”。get_the_time (Y)。>。美元的分隔符。' '; itemprop回声”<=懊姘肌県ref="的。get_month_link (get_the_time (Y), get_the_time (m))。“rel="外部nofollow”>”。get_the_time (F)。>。美元的分隔符。' '; echo $。get_the_time (' d ')。之后美元; }elseif (is_month()){//月存档 itemprop回声”<=懊姘肌県ref="的。get_year_link (get_the_time (Y))。“rel="外部nofollow”rel="外部nofollow”>”。get_the_time (Y)。>。美元的分隔符。' '; echo $。get_the_time (F)。之后美元; }elseif (is_year()){//年存档 echo $。get_the_time (Y)。之后美元; }elseif (is_single () & & ! is_attachment()){//文章 如果(get_post_type () !=皃ost”){//自定义文章类型 $ post_type=get_post_type_object (get_post_type ()); 蛞蝓美元=$ post_type ->重写; itemprop回声”<=懊姘肌県ref="的。求租者美元。“/薄C涝因?“鼻涕虫”)。”/皉el="外部nofollow”>”。-> singular_name $ post_type ->标签。>。美元的分隔符。' '; echo $。get_the_title ()。之后美元; 其他}{//文章 $猫=get_the_category ();猫猫[0]=$美元; (cat_code=get_category_parents美元猫,真的,' '。美元的分隔符。' '); echo $ cat_code=(' <', ' <大小写不敏感itemprop=懊姘肌?cat_code美元); echo $。get_the_title ()。之后美元; } }elseif (! is_single () & & ! is_page () & & get_post_type () !=皃ost”) { $ post_type=get_post_type_object (get_post_type ()); echo $。-> singular_name $ post_type ->标签。之后美元; }elseif (is_attachment()){//附件 (父母=get_post美元post -> post_parent); (猫=get_the_category美元父-> ID);猫猫[0]=$美元; itemprop回声”<=懊姘肌県ref="的。get_permalink(父美元)。“rel="外部nofollow”>”。母公司-> post_title美元。>。美元的分隔符。' '; echo $。get_the_title ()。之后美元; }elseif (is_page () & & ! $ post -> post_parent){//页面 echo $。get_the_title ()。之后美元; }elseif (is_page () & & $ post -> post_parent){//父级页面 美元parent_id=$ post -> post_parent; 数组$面包屑=(); 而(parent_id美元){ (页面=get_page美元parent_id); 面包屑[]=' <美元itemprop=懊姘肌県ref="的。get_permalink($页面-> ID)。“rel="外部nofollow”>”。get_the_title($页面-> ID)。' > '; 美元parent_id=$页面-> post_parent; } (面包屑=array_reverse美元面包屑); foreach(面包屑屑美元美元)echo $碎屑。' '。美元的分隔符。' '; echo $。get_the_title ()。之后美元; }elseif (is_search()){//搜索结果 echo $之前; printf(__(搜索结果:% s, cmp), get_search_query ()); echo $后; }elseif (is_tag()){//标签存档 echo $之前; printf(__(标签档案:% s, cmp), single_tag_title (false)); echo $后; }elseif (is_author()){//作者存档 全球美元的作者; (用户数据=get_userdata美元作者); echo $之前; printf(__(作者档案:% s, cmp),用户数据-> display_name美元); echo $后; }elseif (is_404()){//404页面 echo $之前; _e(“没有找到”,“cmp”); echo $后; } 如果(get_query_var(分页)){//分页 如果(is_category () | | is_day () | | is_month () | | is_year () | | is_search () | | is_tag () | | is_author ()) 回声sprintf (__ ((% s)页,cmp), get_query_var(“分页”)); } 回声的WordPress免插件如何实现面包屑导航的方法