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

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

wordpress网站的内页当中,为了使网站层次表现的更加清晰,让客户明确知道自己当前所在的位置,我们通常会加入面包屑导航功能,英文名叫 Breadcrumb 。下面介绍一下中添加面包屑导航 Breadcrumb 的方法。

1. 切换到主题所在目录,新建一个 breadcrumb.php 文件,加入以下代码:

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-5c891d506fccc816473189-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-2">2
Crayon-num" data-line="Crayon-5c891d506fccc816473189-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-4">4
Crayon-num" data-line="Crayon-5c891d506fccc816473189-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-6">6
Crayon-num" data-line="Crayon-5c891d506fccc816473189-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-8">8
Crayon-num" data-line="Crayon-5c891d506fccc816473189-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-10">10
Crayon-num" data-line="Crayon-5c891d506fccc816473189-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-12">12
Crayon-num" data-line="Crayon-5c891d506fccc816473189-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-14">14
Crayon-num" data-line="Crayon-5c891d506fccc816473189-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-16">16
Crayon-num" data-line="Crayon-5c891d506fccc816473189-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-18">18
Crayon-num" data-line="Crayon-5c891d506fccc816473189-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-20">20
Crayon-num" data-line="Crayon-5c891d506fccc816473189-21">21
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-22">22
Crayon-num" data-line="Crayon-5c891d506fccc816473189-23">23
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-24">24
Crayon-num" data-line="Crayon-5c891d506fccc816473189-25">25
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-26">26
Crayon-num" data-line="Crayon-5c891d506fccc816473189-27">27
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-28">28
Crayon-num" data-line="Crayon-5c891d506fccc816473189-29">29
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d506fccc816473189-30">30
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-5c891d506fccc816473189-1">Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"breadcrumb"
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-2">Crayon-h"> Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-e">bloginfoCrayon-sy">(Crayon-s">'url'Crayon-sy">)Crayon-sy">;Crayon-h"> /"Crayon-h"> Crayon-v">titleCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-e">bloginfoCrayon-sy">(Crayon-s">'name'Crayon-sy">)Crayon-sy">;Crayon-h"> "首页Crayon-o"><Crayon-o">/Crayon-v">aCrayon-o"><Crayon-v">emCrayon-h"> Crayon-o">&Crayon-v">raquoCrayon-sy">;Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">em
Crayon-line" id="Crayon-5c891d506fccc816473189-3">Crayon-h"> Crayon-ta">PHP
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-4">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">is_categoryCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-5">Crayon-h"> Crayon-e">single_cat_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-6">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_searchCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-7">Crayon-h"> Crayon-k ">echoCrayon-h"> Crayon-v">$sCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-8">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_tagCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-9">Crayon-h"> Crayon-e">single_tag_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-10">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_yearCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-11">Crayon-h"> Crayon-e">the_timeCrayon-sy">(Crayon-s">'Y'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-12">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_monthCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-13">Crayon-h"> Crayon-e">the_timeCrayon-sy">(Crayon-s">'Y-m'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-14">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-sy">(Crayon-h"> Crayon-e">is_dayCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-15">Crayon-h"> Crayon-e">the_timeCrayon-sy">(Crayon-s">'Y-m-d'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-16">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_authorCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-17">Crayon-h"> Crayon-k ">echoCrayon-h"> Crayon-s">'Author'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-18">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_singleCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d506fccc816473189-19">Crayon-h"> Crayon-v">$catsCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_the_categoryCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-20">Crayon-h"> Crayon-v">$catCrayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$catsCrayon-sy">[Crayon-cn">0Crayon-sy">]Crayon-sy">;
Crayon-line" id="Crayon-5c891d506fccc816473189-21">Crayon-h"> Crayon-k ">echoCrayon-sy">(Crayon-h"> Crayon-e">get_category_parentsCrayon-sy">(Crayon-v">$catCrayon-i">term_idCrayon-sy">,Crayon-t">trueCrayon-sy">,Crayon-s">' &raquo; 'Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-22">Crayon-h"> Crayon-e">the_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d506fccc816473189-23">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_pageCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-24">Crayon-h"> Crayon-e">the_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d506fccc816473189-25">Crayon-h"> Crayon-sy">}Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-e">is_404Crayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-26">Crayon-h"> Crayon-k ">echoCrayon-h"> Crayon-s">'404 NOT FOUND'Crayon-sy">;
Crayon-line" id="Crayon-5c891d506fccc816473189-27">Crayon-h"> Crayon-sy">}Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-28">Crayon-h"> Crayon-e">wp_reset_queryCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d506fccc816473189-29">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d506fccc816473189-30">Crayon-o"><Crayon-o">/Crayon-v">div

2. 打开page.PHP 或者 category.PHP,在需要显示导航的地方使用下面的代码调用

Crayon-5c891d506fcd6921147488" 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-5c891d506fcd6921147488-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-5c891d506fcd6921147488-1">Crayon-ta">PHPCrayon-h"> Crayon-k ">includeCrayon-sy">(Crayon-s">'breadcrumb.PHP'Crayon-sy">)Crayon-sy">;Crayon-h">

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

至此,一个完美的面包屑导航 Breadcrumb 已经添加完成。

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

猜你在找的wordpress相关文章