- 资源介绍
- 更新记录
- 安装教程
什么是网站面包屑导航?面包屑导航意在告知用户所处的当前网页的位置,方便用户可以通过该导航快速返回上一级网页。
面包屑导航一般都在导航的下面,形式一般为 首页 > 一级目录名称 > 二级目录名称 > 目前位置,尽量要把面包屑导航的层次控制在四层以内,这样也有利与搜索引擎蜘蛛一层层往下爬,到了四层以下就很难爬到了。
面包屑导航的作用
- 让用户了解目前所处位置,以及当前页面在整个网站中的位置。
- 便于搜索引擎对于网站的收录,蜘蛛可以沿着面包屑导航爬下去,便于寻找链接,提高蜘蛛的爬行速度和效率;
- 便于用户了解网站的层次结构,进而浏览网站,提高用户体验;
- 优化面包屑导航每个层级的名称,尽量使用关键字,可以达到更好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里,然后再需要显示面包屑导航的页面添加下面代码即可。
猜你喜欢
-
WordPress SEO优化 如何自动为文章添加标签链接增加站点内链_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress正确引入加载JS、css文件的方法_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress获取文章摘要函数the_excerpt详解_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress搜索结果排除指定页面/文章/自定义分类_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress细节优化之给文章图片自动添加alt和title信息_52弹弹堂-5466shop.cn
2020-08-28 -
了解WordPress的tags标签自定义样式_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress技巧:获取统计文章内图片数量_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress搬家更换域名或者批量数据库修改字符的方法_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress给分类目录添加自定义字段教程_52弹弹堂-5466shop.cn
2020-08-28 -
解决WordPress官网无法访问 429 Too Many Requests_52弹弹堂-5466shop.cn
2020-08-28
-
WordPress文章随机显示缩略图的实现方法_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress 让后台用户列表可以根据文章数进行排序_52弹弹堂-5466shop.cn
2020-08-28 -
wordpress登录界面样式优化_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress移除head头部js、css、feed等多余加载项_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress如何调用全站、同分类随机文章_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress如何在后台显示自带友情链接?_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress不可忽视的面包屑导航SEO优化技巧_52弹弹堂-5466shop.cn
2020-08-28 -
解决WordPress升级时提示正在执行例行维护,请一分钟后回来_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress如何调用指定分类文章_52弹弹堂-5466shop.cn
2020-08-28 -
WordPress如何获取全部文章总浏览数量_52弹弹堂-5466shop.cn
2020-08-28
猜你在找
5466资源网 » WordPress不可忽视的面包屑导航SEO优化技巧_52弹弹堂-5466shop.cn
- 2020-08-28Hi,初次和大家见面了,请多关照!