最新公告
  • 欢迎您光临5466,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!进入交流论坛
  • WordPress不可忽视的面包屑导航SEO优化技巧_52弹弹堂-5466shop.cn

    WordPress不可忽视的面包屑导航SEO优化技巧_52弹弹堂-5466shop.cn 最后编辑:2020-08-28

    什么是网站面包屑导航?面包屑导航意在告知用户所处的当前网页的位置,方便用户可以通过该导航快速返回上一级网页。
    面包屑导航一般都在导航的下面,形式一般为 首页 > 一级目录名称 > 二级目录名称 > 目前位置,尽量要把面包屑导航的层次控制在四层以内,这样也有利与搜索引擎蜘蛛一层层往下爬,到了四层以下就很难爬到了。

    面包屑导航的作用

    1. 让用户了解目前所处位置,以及当前页面在整个网站中的位置。
    2. 便于搜索引擎对于网站的收录,蜘蛛可以沿着面包屑导航爬下去,便于寻找链接提高蜘蛛的爬行速度和效率;
    3. 便于用户了解网站的层次结构,进而浏览网站,提高用户体验
    4. 优化面包屑导航每个层级的名称,尽量使用关键字,可以达到更好SEO优化的效果。

    面包屑导航案例

    //面包屑
    function cmp_breadcrumbs() {
    	$delimiter = \'\'; // 分隔符
    	$before = \'\'; // 在当前链接前插入
    	$after = \'\'; // 在当前链接后插入
    	if ( !is_home() && !is_front_page() || is_paged() ) {
    		echo \'
    \'.__( \'\' , \'cmp\' ); global $post; $homeLink = home_url(); echo \' \' . __( \'首页\' , \'cmp\' ) . \' \' . $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 (\'\' . get_the_time(\'Y\') . \' \' . $delimiter . \' \'; echo \'\' . get_the_time(\'F\') . \' \' . $delimiter . \' \'; echo $before . get_the_time(\'d\') . $after; } elseif ( is_month() ) { // 月 存档 echo \'\' . get_the_time(\'Y\') . \' \' . $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 \'\' . $post_type->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, TRUE, \' \' . $delimiter . \' \'); echo $cat_code = str_replace (\'labels->singular_name . $after; } elseif ( is_attachment() ) { // 附件 $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo \'\' . $parent->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) . \'\" rel=\"external nofollow\" >\' . get_the_title($page->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( __( \'搜索「%s」的结果如下:\', \'cmp\' ), get_search_query() ); echo $after; } elseif ( is_tag() ) { //标签 存档 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 页面 echo $before; _e( \'没有找到\', \'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 )\', \'cmp\' ), get_query_var(\'paged\') ); } echo \'
    \'; } }

    使用方法

    将上面WordPress代码复制粘贴到自己主题的functions.php里,然后再需要显示面包屑导航的页面添加下面代码即可。

    
    

     

    猜你喜欢

    猜你在找

    1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!7345947@qq.com 2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理,有奖励! 3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负! 4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
    5466资源网 » WordPress不可忽视的面包屑导航SEO优化技巧_52弹弹堂-5466shop.cn
    • 2020-08-28Hi,初次和大家见面了,请多关照!

    发表回复

    • 383会员总数(位)
    • 41554资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 1156稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情