WordPress建站中添加面包屑导航Breadcrumb的方法二

前端之家收集整理的这篇文章主要介绍了WordPress建站中添加面包屑导航Breadcrumb的方法二前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

上一篇文章中,我们介绍了 wordpress添加面包屑导航 Breadcrumb 的一种方法,也阐述了添加面包屑导航 Breadcrumb 的原因。下面我们再介绍另外一种中添加面包屑导航 Breadcrumb 的方法。

1. 切换到主题目录,打开functions.php文件,添加如下代码:

' . $delimiter . ' '; if ( is_category() ) { // 分类 存档 global $wp_query; $cat_obj = $wp_query->get_queried_object(); $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0){ $cat_code = get_category_parents($parentCat,TRUE,' ' . $delimiter . ' '); echo $cat_code = str_replace (' ' . $delimiter . ' '; echo ' ' . $delimiter . ' '; echo $before . get_the_time('d') . $after; } elseif ( is_month() ) { // 月 存档 echo ' ' . $delimiter . ' '; echo $before . get_the_time('F') . $after; } elseif ( is_year() ) { // 年 存档 echo $before . get_the_time('Y') . $after; } elseif ( is_single() && !is_attachment() ) { // 文章 if ( get_post_type() != 'post' ) { // 自定义文章类型 $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo 'labels->singular_name . ' ' . $delimiter . ' '; echo $before . get_the_title() . $after; } else { // 文章 post $cat = get_the_category(); $cat = $cat[0]; $cat_code = get_category_parents($cat,$cat_code ); echo $before . get_the_title() . $after; } } elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif ( is_attachment() ) { // 附件 $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo 'post_title . ' ' . $delimiter . ' '; echo $before . get_the_title() . $after; } elseif ( is_page() && !$post->post_parent ) { // 页面 echo $before . get_the_title() . $after; } elseif ( is_page() && $post->post_parent ) { // 父级页面 $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = 'ID) . ''; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' '; echo $before . get_the_title() . $after; } elseif ( is_search() ) { // 搜索结果 echo $before ; printf( __( 'Search Results for: %s','cmp' ),get_search_query() ); echo $after; } elseif ( is_tag() ) { //标签 存档 echo $before ; printf( __( 'Tag Archives: %s',single_tag_title( '',false ) ); echo $after; } elseif ( is_author() ) { // 作者存档 global $author; $userdata = get_userdata($author); echo $before ; printf( __( 'Author Archives: %s',$userdata->display_name ); echo $after; } elseif ( is_404() ) { // 404 页面 echo $before; _e( 'Not Found','cmp' ); echo $after; } if ( get_query_var('paged') ) { // 分页 if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo sprintf( __( '( Page %s )',get_query_var('paged') ); } echo '
'; } }
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-2">2
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-4">4
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-6">6
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-8">8
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-10">10
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-12">12
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-14">14
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-16">16
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-18">18
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-20">20
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-21">21
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-22">22
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-23">23
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-24">24
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-25">25
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-26">26
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-27">27
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-28">28
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-29">29
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-30">30
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-31">31
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-32">32
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-33">33
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-34">34
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-35">35
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-36">36
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-37">37
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-38">38
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-39">39
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-40">40
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-41">41
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-42">42
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-43">43
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-44">44
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-45">45
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-46">46
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-47">47
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-48">48
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-49">49
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-50">50
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-51">51
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-52">52
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-53">53
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-54">54
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-55">55
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-56">56
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-57">57
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-58">58
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-59">59
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-60">60
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-61">61
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-62">62
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-63">63
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-64">64
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-65">65
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-66">66
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-67">67
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-68">68
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-69">69
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-70">70
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-71">71
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-72">72
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-73">73
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-74">74
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-75">75
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-76">76
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-77">77
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-78">78
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-79">79
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-80">80
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-81">81
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-82">82
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-83">83
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-84">84
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-85">85
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-86">86
Crayon-num" data-line="Crayon-5c891d4fc2fc4574984196-87">87
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4fc2fc4574984196-88">88
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-1">Crayon-t">functionCrayon-h"> Crayon-e">ss_breadcrumbsCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-2">Crayon-h">Crayon-sy">$Crayon-v">delimiterCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'»'Crayon-sy">;Crayon-h"> Crayon-c">// 分隔符
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-3">Crayon-h">Crayon-sy">$Crayon-v">beforeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'Crayon-sy">;Crayon-h"> Crayon-c">// 在当前链接前插入
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-4">Crayon-h">Crayon-sy">$Crayon-v">afterCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">''Crayon-sy">;Crayon-h"> Crayon-c">// 在当前链接后插入
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-5">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-o">!Crayon-e">is_homeCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">&&Crayon-h"> Crayon-o">!Crayon-e">is_front_pageCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_pagedCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-6">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">'
Crayon-sy">.Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'当前位置:'Crayon-h"> Crayon-sy">,Crayon-h"> Crayon-s">'cmp'Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-7">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">postCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-8">Crayon-h">Crayon-sy">$Crayon-v">homeLinkCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">home_urlCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-9">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-10">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_categoryCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 分类 存档
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-11">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">wp_queryCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-12">Crayon-h">Crayon-sy">$Crayon-v">cat_objCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">wp_queryCrayon-e">get_queried_objectCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-13">Crayon-h">Crayon-sy">$Crayon-v">thisCatCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">cat_objCrayon-v">term_idCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-14">Crayon-h">Crayon-sy">$Crayon-v">thisCatCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_categoryCrayon-sy">(Crayon-sy">$Crayon-v">thisCatCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-15">Crayon-h">Crayon-sy">$Crayon-v">parentCatCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_categoryCrayon-sy">(Crayon-sy">$Crayon-v">thisCatCrayon-r">parentCrayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-16">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-v">thisCatCrayon-r">parentCrayon-h"> Crayon-o">!=Crayon-h"> Crayon-cn">0Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-17">Crayon-h">Crayon-sy">$Crayon-v">cat_codeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_category_parentsCrayon-sy">(Crayon-sy">$Crayon-v">parentCatCrayon-sy">,Crayon-h"> Crayon-t">TRUECrayon-sy">,Crayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-18">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-v">cat_codeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">str_replaceCrayon-h"> Crayon-sy">(Crayon-s">'code
'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-23">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-24">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_timeCrayon-sy">(Crayon-s">'d'Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-25">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_monthCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 月 存档
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-26">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-27">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_timeCrayon-sy">(Crayon-s">'F'Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-28">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_yearCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 年 存档
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-29">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_timeCrayon-sy">(Crayon-s">'Y'Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-30">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_singleCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">&&Crayon-h"> Crayon-o">!Crayon-e">is_attachmentCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 文章
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-31">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">get_post_typeCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">!=Crayon-h"> Crayon-s">'post'Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 自定义文章类型
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-32">Crayon-h">Crayon-sy">$Crayon-v">post_typeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_post_type_objectCrayon-sy">(Crayon-e">get_post_typeCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-33">Crayon-h">Crayon-sy">$Crayon-v">slugCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">post_typeCrayon-v">rewriteCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-34">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">'name 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-35">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_titleCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-36">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseCrayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 文章 post
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-37">Crayon-h">Crayon-sy">$Crayon-v">catCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_the_categoryCrayon-sy">(Crayon-sy">)Crayon-sy">;Crayon-h"> Crayon-sy">$Crayon-v">catCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">catCrayon-sy">[Crayon-cn">0Crayon-sy">]Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-38">Crayon-h">Crayon-sy">$Crayon-v">cat_codeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_category_parentsCrayon-sy">(Crayon-sy">$Crayon-v">catCrayon-sy">,Crayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-39">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-v">cat_codeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">str_replaceCrayon-h"> Crayon-sy">(Crayon-s">'code
name
title 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-49">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_titleCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-50">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_pageCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">&&Crayon-h"> Crayon-o">!Crayon-sy">$Crayon-v">postCrayon-v">postCrayon-sy">_parentCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 页面
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-51">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_titleCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-52">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_pageCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">&&Crayon-h"> Crayon-sy">$Crayon-v">postCrayon-v">postCrayon-sy">_parentCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 父级页面
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-53">Crayon-h">Crayon-sy">$Crayon-v">parent_idCrayon-h">Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">postCrayon-v">post_parentCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-54">Crayon-h">Crayon-sy">$Crayon-v">breadcrumbsCrayon-h"> Crayon-o">=Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-55">Crayon-h">Crayon-st">whileCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-v">parent_idCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-56">Crayon-h">Crayon-sy">$Crayon-v">pageCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_pageCrayon-sy">(Crayon-sy">$Crayon-v">parent_idCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-57">Crayon-h">Crayon-sy">$Crayon-v">breadcrumbsCrayon-sy">[Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">''Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-58">Crayon-h">Crayon-sy">$Crayon-v">parent_idCrayon-h">Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">pageCrayon-v">post_parentCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-59">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-60">Crayon-h">Crayon-sy">$Crayon-v">breadcrumbsCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">array_reverseCrayon-sy">(Crayon-sy">$Crayon-v">breadcrumbsCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-61">Crayon-h">Crayon-st">foreachCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-e">breadcrumbs Crayon-st">asCrayon-h"> Crayon-sy">$Crayon-v">crumbCrayon-sy">)Crayon-h"> Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">crumbCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-i">delimiterCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">' 'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-62">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">get_the_titleCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-63">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_searchCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 搜索结果
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-64">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-65">Crayon-h">Crayon-e">printfCrayon-sy">(Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'Search Results for: %s'Crayon-sy">,Crayon-h"> Crayon-s">'cmp'Crayon-h"> Crayon-sy">)Crayon-sy">,Crayon-h">Crayon-e">get_search_queryCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-66">Crayon-h">Crayon-i">echoCrayon-h">Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-67">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_tagCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">//标签 存档
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-68">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-69">Crayon-h">Crayon-e">printfCrayon-sy">(Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'Tag Archives: %s'Crayon-sy">,Crayon-h"> Crayon-e">single_tag_titleCrayon-sy">(Crayon-h"> Crayon-s">''Crayon-sy">,Crayon-h"> Crayon-t">falseCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-70">Crayon-h">Crayon-i">echoCrayon-h">Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-71">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_authorCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 作者存档
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-72">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">authorCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-73">Crayon-h">Crayon-sy">$Crayon-v">userdataCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_userdataCrayon-sy">(Crayon-sy">$Crayon-v">authorCrayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-74">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-i">beforeCrayon-h"> Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-75">Crayon-h">Crayon-e">printfCrayon-sy">(Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'Author Archives: %s'Crayon-sy">,Crayon-h">Crayon-sy">$Crayon-v">userdataCrayon-v">displayCrayon-sy">_nameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-76">Crayon-h">Crayon-i">echoCrayon-h">Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-77">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_404Crayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 404 页面
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-78">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-sy">$Crayon-v">beforeCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-79">Crayon-h">Crayon-e">_eCrayon-sy">(Crayon-h"> Crayon-s">'Not Found'Crayon-sy">,Crayon-h"> Crayon-s">'cmp'Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-80">Crayon-h">Crayon-i">echoCrayon-h">Crayon-sy">$Crayon-v">afterCrayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-81">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-82">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">get_query_varCrayon-sy">(Crayon-s">'paged'Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h"> Crayon-c">// 分页
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-83">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_categoryCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_dayCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_monthCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_yearCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_searchCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_tagCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-o">||Crayon-h"> Crayon-e">is_authorCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-84">Crayon-h">Crayon-e">echo Crayon-e">sprintfCrayon-sy">(Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'( Page %s )'Crayon-sy">,Crayon-h"> Crayon-e">get_query_varCrayon-sy">(Crayon-s">'paged'Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-85">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-86">Crayon-h">Crayon-i">echoCrayon-h"> Crayon-s">'
'
Crayon-sy">;
Crayon-line" id="Crayon-5c891d4fc2fc4574984196-87">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4fc2fc4574984196-88">Crayon-sy">}

2. 在主题的page.PHP 或者category.PHP文件中,使用如下代码调用

Crayon-5c891d4fc2fce630886460" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">page.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d4fc2fce630886460-1">1
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d4fc2fce630886460-1">Crayon-ta">PHPCrayon-h"> Crayon-st">ifCrayon-sy">(Crayon-e">function_existsCrayon-sy">(Crayon-s">'ss_breadcrumbs'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-e">ss_breadcrumbsCrayon-sy">(Crayon-sy">)Crayon-sy">;

3. 通过css代码定义导航的样式,美化显示效果

完成,以上便是 wordpress添加面包屑导航 Breadcrumb的另外一种方法

原文链接:https://www.f2er.com/wordpress/238513.html

猜你在找的wordpress相关文章