WordPress 添加面包屑导的三种方法.docx

上传人:s9****2 文档编号:550924548 上传时间:2024-01-31 格式:DOCX 页数:10 大小:69KB
返回 下载 相关 举报
WordPress 添加面包屑导的三种方法.docx_第1页
第1页 / 共10页
WordPress 添加面包屑导的三种方法.docx_第2页
第2页 / 共10页
WordPress 添加面包屑导的三种方法.docx_第3页
第3页 / 共10页
WordPress 添加面包屑导的三种方法.docx_第4页
第4页 / 共10页
WordPress 添加面包屑导的三种方法.docx_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《WordPress 添加面包屑导的三种方法.docx》由会员分享,可在线阅读,更多相关《WordPress 添加面包屑导的三种方法.docx(10页珍藏版)》请在金锄头文库上搜索。

1、-云客网 您网站的流量加油站WordPress 添加面包屑导航的三种方法 面包屑导航,简单的说它就是提供给用户回溯到网站首页或入口页面的一条快速路径。今天倡萌分享一下WordPress 添加面包屑导航的三种方法,希望对大家有所帮助,原文参考自园子博客。什么是面包屑导航面包屑通常出现在页面顶部,一般会位于标题或页头的下方。它提供给用户返回之前任何一个页面的链接(这些链接也是能到达当前页面的路径),在层级架构中通常是这个页面的父级页面。也可以这样理解,面包屑提供给用户回溯到网站首页或入口页面的一条快速路径,它们绝大部分看起来就像这样:首页分类页次级分类页。如下图所示:面包屑导航的好处1.可以提供多

2、路径的交互方式,方便用户跳转到其它页面。在页面及分类多的网站中尤其有用。2.面包屑导航信息结构对于网站的seo也有着大的好处,它可以更多的强调网站关键字,扩大关键字的范围,从而达到更好的优化目的。3.它从一个侧面展示了该信息集合的信息结构和集合方式,可以让用户在最快的时间之内找到需要的东西。添加面包屑导航的方法方法一:直接在相关页面添加代码把以下代码直接添加到你想出现面包屑导航的位置,比如 header.php 里面,也可以放在 single.php 页面的导航标题上面,你有可能需要添加的页面可能有:archive.php、archives.php、links.php、page.php。123

3、45678910111213141516171819202122232425当前位置: if( is_single() )$categorys = get_the_category();$category = $categorys0;echo( get_category_parents($category-term_id,true, ) );the_title(); elseif ( is_page() )the_title(); elseif ( is_category() )single_cat_title(); elseif ( is_tag() )single_tag_title();

4、 elseif ( is_day() )the_time(Y年Fj日); elseif ( is_month() )the_time(Y年F); elseif ( is_year() )the_time(Y年); elseif ( is_search() )echo $s. 的搜索结果;?此法来自万戈博客,原文链接方法二:通过 functions.php 调用首先把以下代码添加到主题的 functions.php 文件中function dimox_breadcrumbs() $delimiter = ;$name = Home; /text for the Home link$current

5、Before = ;$currentAfter = ;if ( !is_home() & !is_front_page() | is_paged() ) echo ; global $post;$home = get_bloginfo(url);echo . $name . . $delimiter . ;if ( is_category() ) global $wp_query;$cat_obj = $wp_query-get_queried_object();$thisCat = $cat_obj-term_id;$thisCat = get_category($thisCat);$par

6、entCat = get_category($thisCat-parent);if ($thisCat-parent != 0) echo(get_category_parents($parentCat, TRUE, . $delimiter . );echo $currentBefore . Archive by category ;single_cat_title();echo . $currentAfter; elseif ( is_day() ) echo . get_the_time(Y) . . $delimiter . ;echo . get_the_time(F) . . $d

7、elimiter . ;echo $currentBefore . get_the_time(d) . $currentAfter; elseif ( is_month() ) echo . get_the_time(Y) . . $delimiter . ;echo $currentBefore . get_the_time(F) . $currentAfter; elseif ( is_year() ) echo $currentBefore . get_the_time(Y) . $currentAfter; elseif ( is_single() ) $cat = get_the_c

8、ategory(); $cat = $cat0;echo get_category_parents($cat, TRUE, . $delimiter . );echo $currentBefore;the_title();echo $currentAfter; elseif ( is_page() & !$post-post_parent ) echo $currentBefore;the_title();echo $currentAfter; elseif ( is_page() & $post-post_parent ) $parent_id = $post-post_parent;$br

9、eadcrumbs = array();while ($parent_id) $page = get_page($parent_id);$breadcrumbs = . get_the_title($page-ID) . ;$parent_id = $page-post_parent;$breadcrumbs = array_reverse($breadcrumbs);foreach ($breadcrumbs as $crumb) echo $crumb . . $delimiter . ;echo $currentBefore;the_title();echo $currentAfter;

10、 elseif ( is_search() ) echo $currentBefore . Search results for . get_search_query() . . $currentAfter; elseif ( is_tag() ) echo $currentBefore . Posts tagged ;single_tag_title();echo . $currentAfter; elseif ( is_author() ) global $author;$userdata = get_userdata($author);echo $currentBefore . Arti

11、cles posted by . $userdata-display_name . $currentAfter; elseif ( is_404() ) echo $currentBefore . Error 404 . $currentAfter;if ( get_query_var(paged) ) if ( is_category() | is_day() | is_month() | is_year() | is_search() | is_tag() | is_author() ) echo (;echo _(Page) . . get_query_var(paged);if ( i

12、s_category() | is_day() | is_month() | is_year() | is_search() | is_tag() | is_author() ) echo );echo ;最后在适当的地方(如方法一中提到的几个文件)添加以下代码调用如果想要美化下显示方式,直接通过添加 css 即可。1.mbx-dh padding: 5px 10px;方法三:使用Breadcrumb NavXT插件在后台,添加新插件,搜索“Breadcrumb NavXT” 安装、激活。然后在header.php中合适的地方增加代码:123这个插件还可以设置,进入设置选项后,共有genera

13、l、current item、posts&pages、categories、tags、date archives、miscellaneous等相关设置。1.general设置(一般设置)可以设置面包屑导航的分割符(Breadcrumb Separator)Breadcrumb Max Title Length设置面包屑导航标题的最大长度Home Breadcrumb主页的标题Place the home breadcrumb in the trail:如果打勾的话表示在面包屑导航中显示主页,不打勾的话则不显示。Home Title填入主页的显示标题,默认是blog,你可以修改为你想要的标题。Home Prefix(主页前缀)可以在主页前面添加说明文字。Home Suffix(主页后缀)在主页后面添加说明文字Home Anchor、Blog Anchor一般不需要修改,插件会自动生成链接。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号