最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WordPress免插件實(shí)現(xiàn)面包屑導(dǎo)航的示例代碼

 更新時(shí)間:2020年08月20日 14:02:12   作者:511遇見(jiàn)  
這篇文章主要介紹了WordPress免插件實(shí)現(xiàn)面包屑導(dǎo)航,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

你如果在開(kāi)發(fā)自己的wordpress主題,想加入面包屑導(dǎo)航,而又不想使用插件的話(huà),下面的代碼對(duì)你有幫助,這里提供了網(wǎng)上較為流行的兩種代碼,一是功能非常完善的,一是一個(gè)較為簡(jiǎn)潔的代碼。

前面介紹了一種方法,你也可以嘗試一下,在文末給大家詳細(xì)介紹了自定義函數(shù)實(shí)現(xiàn)wordpress面包屑導(dǎo)航的代碼,可以點(diǎn)擊查看下。

功能非常完善代碼

1、將下面的代碼添加到主題的 functions.php

/**
 * WordPress 添加面包屑導(dǎo)航 
 * http://www.511yj.com/wordpress-add-breadcrumb.html
 */
function cmp_breadcrumbs() {
 $delimiter = '»'; // 分隔符
 $before = '<span class="current">'; // 在當(dāng)前鏈接前插入
 $after = '</span>'; // 在當(dāng)前鏈接后插入
 if ( !is_home() && !is_front_page() || is_paged() ) {
 echo '<div itemscope itemtype="http://schema.org/WebPage" id="crumbs">'.__( '當(dāng)前位置:' , 'cmp' );
 global $post;
 $homeLink = home_url();
 echo ' <a itemprop="breadcrumb" href="' . $homeLink . '" rel="external nofollow" >' . __( '無(wú)作為' , 'cmp' ) . '</a> ' . $delimiter . ' ';
 if ( is_category() ) { // 分類(lèi) 存檔
 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 ('<a','<a itemprop="breadcrumb"', $cat_code );
 }
 echo $before . '' . single_cat_title('', false) . '' . $after;
 } elseif ( is_day() ) { // 天 存檔
 echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '" rel="external nofollow" rel="external nofollow" >' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
 echo '<a itemprop="breadcrumb" href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '" rel="external nofollow" >' . get_the_time('F') . '</a> ' . $delimiter . ' ';
 echo $before . get_the_time('d') . $after;
 } elseif ( is_month() ) { // 月 存檔
 echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '" rel="external nofollow" rel="external nofollow" >' . get_the_time('Y') . '</a> ' . $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' ) { // 自定義文章類(lèi)型
 $post_type = get_post_type_object(get_post_type());
 $slug = $post_type->rewrite;
 echo '<a itemprop="breadcrumb" href="' . $homeLink . '/' . $slug['slug'] . '/" rel="external nofollow" >' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
 echo $before . get_the_title() . $after;
 } else { // 文章 post
 $cat = get_the_category(); $cat = $cat[0];
 $cat_code = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
 echo $cat_code = str_replace ('<a','<a itemprop="breadcrumb"', $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 '<a itemprop="breadcrumb" href="' . get_permalink($parent) . '" rel="external nofollow" >' . $parent->post_title . '</a> ' . $delimiter . ' ';
 echo $before . get_the_title() . $after;
 } elseif ( is_page() && !$post->post_parent ) { // 頁(yè)面
 echo $before . get_the_title() . $after;
 } elseif ( is_page() && $post->post_parent ) { // 父級(jí)頁(yè)面
 $parent_id = $post->post_parent;
 $breadcrumbs = array();
 while ($parent_id) {
 $page = get_page($parent_id);
 $breadcrumbs[] = '<a itemprop="breadcrumb" href="' . get_permalink($page->ID) . '" rel="external nofollow" >' . get_the_title($page->ID) . '</a>';
 $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() ) { // 搜索結(jié)果
 echo $before ;
 printf( __( 'Search Results for: %s', 'cmp' ), get_search_query() );
 echo $after;
 } elseif ( is_tag() ) { //標(biāo)簽 存檔
 echo $before ;
 printf( __( 'Tag Archives: %s', 'cmp' ), single_tag_title( '', false ) );
 echo $after;
 } elseif ( is_author() ) { // 作者存檔
 global $author;
 $userdata = get_userdata($author);
 echo $before ;
 printf( __( 'Author Archives: %s', 'cmp' ), $userdata->display_name );
 echo $after;
 } elseif ( is_404() ) { // 404 頁(yè)面
 echo $before;
 _e( 'Not Found', 'cmp' );
 echo $after;
 }
 if ( get_query_var('paged') ) { // 分頁(yè)
 if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() )
 echo sprintf( __( '( Page %s )', 'cmp' ), get_query_var('paged') );
 }
 echo '</div>';
 }
}

前臺(tái)調(diào)用

<?php if(function_exists('cmp_breadcrumbs')) cmp_breadcrumbs();?>

下面看下自定義函數(shù)實(shí)現(xiàn)wordpress面包屑導(dǎo)航的代碼

面包屑導(dǎo)航 一是方便讀者所在的位置,更重要的是對(duì)SEO非常友好,利于蜘蛛知道你網(wǎng)站的目錄結(jié)構(gòu),所以給我們的wordpress主題添加面包屑導(dǎo)航是必須的。

1、在functioss.php添加以下代碼

/**
 * WordPress 添加面包屑導(dǎo)航 
 * 面包屑導(dǎo)航,直接輸出(echo)
 * Breadcrumb Trail
 * @param string $sep 導(dǎo)航對(duì)象分隔符,默認(rèn)為' > '
 */
function bread_nav($sep = ' > '){
  echo '<div class="col-md-12 "><span class="glyphicon glyphicon-home text-primary"></span> 您當(dāng)前的位置: <a href="'. home_url() .'" title="首頁(yè)">首頁(yè)</a>';
  if ( is_category() ){  //如果是欄目頁(yè)面
    global $cat;    
    echo $sep . get_category_parents($cat, true, $sep) . '文章列表';
  }elseif ( is_page() ){  //如果是自定義頁(yè)面
    echo $sep . get_the_title();
  }elseif ( is_single() ){  //如果是文章頁(yè)面
    $categories = get_the_category();
    $cat = $categories[0];
    echo $sep . get_category_parents($cat->term_id, true, $sep) .'正文內(nèi)容 '. get_the_title(); 
  }
  echo '</div>';
}

2、前臺(tái)調(diào)用

 <?php bread_nav();?>

總結(jié)

到此這篇關(guān)于WordPress免插件實(shí)現(xiàn)面包屑導(dǎo)航的示例代碼的文章就介紹到這了,更多相關(guān)WordPress面包屑導(dǎo)航內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用php操作xml教程

    使用php操作xml教程

    這篇文章主要介紹了使用php操作xml教程,本篇文章通過(guò)簡(jiǎn)要的案例和文檔描述,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • laravel安裝和配置教程

    laravel安裝和配置教程

    這篇文章主要介紹了laravel安裝和配置教程,需要的朋友可以參考下
    2014-10-10
  • PHP 二維數(shù)組和三維數(shù)組的過(guò)濾

    PHP 二維數(shù)組和三維數(shù)組的過(guò)濾

    本文給大家介紹PHP 二維數(shù)組和三維數(shù)組的過(guò)濾,涉及到php三維數(shù)組變二維數(shù)組的相關(guān)知識(shí),本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧
    2016-03-03
  • PHP中__get()和__set()的用法實(shí)例詳解

    PHP中__get()和__set()的用法實(shí)例詳解

    在PHP5中,預(yù)定義了兩個(gè)函數(shù)“__get()”和“__set()”來(lái)獲取和賦值其屬性,對(duì)每個(gè)字段進(jìn)行set和get的操作。只需要加上兩個(gè)魔術(shù)方法即可
    2013-06-06
  • php-fpm配置詳解

    php-fpm配置詳解

    這篇文章主要介紹了php-fpm配置詳解,需要的朋友可以參考下
    2014-02-02
  • ThinkPHP3.1新特性之G方法的使用

    ThinkPHP3.1新特性之G方法的使用

    ThinkPHP3.1的G方法的作用包括標(biāo)記位置和區(qū)間統(tǒng)計(jì)兩個(gè)功能。這篇文章主要介紹了ThinkPHP3.1版G方法的使用,需要的朋友可以參考下
    2014-06-06
  • PHP開(kāi)發(fā)api接口安全驗(yàn)證的實(shí)例講解

    PHP開(kāi)發(fā)api接口安全驗(yàn)證的實(shí)例講解

    下面小編就為大家分享一篇PHP開(kāi)發(fā)api接口安全驗(yàn)證的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • php讀取EXCEL文件 php excelreader讀取excel文件

    php讀取EXCEL文件 php excelreader讀取excel文件

    php開(kāi)發(fā)中肯定會(huì)遇到將excel文件內(nèi)容導(dǎo)入到數(shù)據(jù)庫(kù)的需要,php-excel-reader可以很輕松的使用它讀取excel文件,本文將詳細(xì)介紹,需要了解的朋友可以參考下
    2012-12-12
  • laravel 解決crontab不執(zhí)行的問(wèn)題

    laravel 解決crontab不執(zhí)行的問(wèn)題

    今天小編就為大家分享一篇laravel 解決crontab不執(zhí)行的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • 淺談laravel框架sql中g(shù)roupBy之后排序的問(wèn)題

    淺談laravel框架sql中g(shù)roupBy之后排序的問(wèn)題

    今天小編就為大家分享一篇淺談laravel框架sql中g(shù)roupBy之后排序的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10

最新評(píng)論

柘城县| 庄浪县| 襄垣县| 清镇市| 富源县| 泰州市| 三门峡市| 云霄县| 天祝| 兴仁县| 新平| 皋兰县| 张家口市| 历史| 临潭县| 会泽县| 宁津县| 桐梓县| 开江县| 闽清县| 贡嘎县| 岳池县| 大庆市| 忻州市| 阳泉市| 石狮市| 景东| 秦安县| 大宁县| 岳阳县| 靖远县| 吴江市| 鸡东县| 扎赉特旗| 富宁县| 连城县| 巩留县| 昆山市| 龙南县| 福海县| 墨玉县|