WordPress不可忽视的面包屑导航SEO优化技巧

2020-06-20 0 828
资源下载
终身会员专享

WordPress不可忽视的面包屑导航SEO优化技巧

2020-06-20资源编号:1314DIV CSS8280
如侵权、投诉或获取更新,请联系作者处理
文章目录

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

  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 ('<a','<a itemprop="breadcrumb"', $cat_code ); } echo $before . '' . single_cat_title('', false) . '' . $after; } elseif ( is_day() ) { // 天 存档 echo '' . 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 ('<a','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里,然后再需要显示面包屑导航的页面添加下面代码即可。


 

文章来自小白学习资源站https://qyymz.com转载请注明出处,谢谢!!!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

千源源码站 DIV CSS WordPress不可忽视的面包屑导航SEO优化技巧 https://qyymz.com/13956.html

常见问题

相关文章

猜你喜欢
发表评论
暂无评论