如何用纯代码方法实现WordPress面包屑导航效果
1、层级较深的网站,面包屑导航适合层级较深的网站,如果只有一级分类的话,通过主导航就可以起到快速定位的作用。
比如“豆瓣网”类型扁平构架的网站就没有使用面包屑导航的作用。
2、独立不交叉的网站机构,由于面包屑网站导航路径是线性结构的,因此网站内容必须划分的非常清晰,且不存在交叉;否则,面包屑导航的路径就不是唯一的,同一分类可能出现在不同的路径中,让用户感到困惑。
在wordpress中添加面包屑导航的话,可以直接使用插件来实现,不过很多站长都不喜欢用插件,还是认为如果能用代码解决的话是最理想的。
我最近也找了一些关于面包屑导航的资料。
下文中就有详细解决怎么用代码来实现wordpress面包屑导航:一、在wordpress博客当前主题的functions.php文件(没有就创建一个)中添加以下代码://面包屑导航function get_breadcrumbs(){ global $wp_query; if ( !is_home() ){ // Start the UL echo ''; // Add the Home link echo ''. get_bloginfo('name') .''; if ( is_category() ) { $catTitle = single_cat_title( "", false ); $cat = get_cat_ID( $catTitle ); echo " ? ". get_category_parents( $cat, TRUE, " ? " ) .""; } elseif ( is_archive() && !is_category() ) { echo " ? Archives"; } elseif ( is_search() ) { echo " ? Search Results"; } elseif ( is_404() ) { echo " ? 404 Not Found"; } elseif ( is_single() ) { $category = get_the_category(); $category_id = get_cat_ID( $category[0]->cat_name ); echo ' ? '. get_category_parents( $category_id, TRUE, " ? " ); echo the_title('','', FALSE) .""; } elseif ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo " ? ".the_title('','', FALSE).""; } else { $title = the_title('','', FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor ){ if( $ancestor != end($ancestors) ){ echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } else { echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } } } } // End the UL echo ""; }}二、在显示面包屑导航的位置添加以下调用代码:三、在主题的css样式文件中添加以下样式代码:ul.breadcrumbs {list-style: none; font-size:12px;}ul.breadcrumbs li {float: left; margin-right:5px;}
怎样制作wordpress的面包屑导航
如果是新手, 建议用其他Wordpress 的插件。
例如Yoast SEO 或者 WP SEO 他们都有加面包屑的功能, 如果不想加插件, 可以把以下加进function.php // Breadcrumbs function custom_breadcrumbs() { // Settings $separator = '>'; $breadcrums_id = 'breadcrumbs'; $breadcrums_class = 'breadcrumbs'; $home_title = 'Homepage'; // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat) $custom_taxonomy = 'product_cat'; // Get the query & post information global $post,$wp_query; // Do not display on the homepage if ( !is_front_page() ) { // Build the breadcrums echo ''; // Home page echo '' . $home_title . ''; echo ' ' . $separator . ' '; if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) { echo '' . post_type_archive_title($prefix, false) . ''; } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } $custom_tax_name = get_queried_object()->name; echo '' . $custom_tax_name . ''; } else if ( is_single() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } // Get post category info $category = get_the_category(); if(!empty($category)) { // Get last category post is in $last_category = end(array_values($category)); // Get parent any categories and create array $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),','); $cat_parents = explode(',',$get_cat_parents); // Loop through parent categories and store in variable $cat_display $cat_display = ''; foreach($cat_parents as $parents) { $cat_display .= ''.$parents.''; $cat_display .= ' ' . $separator . ' '; } } // If it's a custom post type within a custom taxonomy $taxonomy_exists = taxonomy_exists($custom_taxonomy); if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) { $taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy ); $cat_id = $taxonomy_terms[0]->term_id; $cat_nicename = $taxonomy_terms[0]->slug; $cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy); $cat_name = $taxonomy_terms[0]->name; } // Check if the post is in a category if(!empty($last_category)) { echo $cat_display; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; // Else if post is in a custom taxonomy } else if(!empty($cat_id)) { echo '' . $cat_name . ''; echo ' ' . $separator . ' '; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } else { echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } } else if ( is_category() ) { // Category page echo '' . single_cat_title('', false) . ''; } else if ( is_page() ) { // Standard page if( $post->post_parent ){ // If child page, get parents $anc = get_post_ancestors( $post->ID ); // Get parents in the right order $anc = array_reverse($anc); // Parent page loop if ( !isset( $parents ) ) $parents = null; foreach ( $anc as $ancestor ) { $parents .= '' . get_the_title($ancestor) . ''; $parents .= ' ' . $separator . ' '; } // Display parent pages echo $parents; // Current page echo 'ID . '"> ' . get_the_title() . ''; } else { // Just display current page if not parents echo 'ID . '">ID . '"> ' . get_the_title() . ''; } } echo ''; } }
怎样制作wordpress的面包屑导航
展开全部 如果是新手, 建议用其他Wordpress 的插件。
例如Yoast SEO 或者 WP SEO 他们都有加面包屑的功能, 如果不想加插件, 可以把以下加进function.php // Breadcrumbsfunction custom_breadcrumbs() { // Settings $separator = '>'; $breadcrums_id = 'breadcrumbs'; $breadcrums_class = 'breadcrumbs'; $home_title = 'Homepage'; // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat) $custom_taxonomy = 'product_cat'; // Get the query & post information global $post,$wp_query; // Do not display on the homepage if ( !is_front_page() ) { // Build the breadcrums echo ''; // Home page echo '' . $home_title . ''; echo ' ' . $separator . ' '; if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) { echo '' . post_type_archive_title($prefix, false) . ''; } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } $custom_tax_name = get_queried_object()->name; echo '' . $custom_tax_name . ''; } else if ( is_single() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } // Get post category info $category = get_the_category(); if(!empty($category)) { // Get last category post is in $last_category = end(array_values($category)); // Get parent any categories and create array $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),','); $cat_parents = explode(',',$get_cat_parents); // Loop through parent categories and store in variable $cat_display $cat_display = ''; foreach($cat_parents as $parents) { $cat_display .= ''.$parents.''; $cat_display .= ' ' . $separator . ' '; } } // If it's a custom post type within a custom taxonomy $taxonomy_exists = taxonomy_exists($custom_taxonomy); if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) { $taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy ); $cat_id = $taxonomy_terms[0]->term_id; $cat_nicename = $taxonomy_terms[0]->slug; $cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy); $cat_name = $taxonomy_terms[0]->name; } // Check if the post is in a category if(!empty($last_category)) { echo $cat_display; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; // Else if post is in a custom taxonomy } else if(!empty($cat_id)) { echo '' . $cat_name . ''; echo ' ' . $separator . ' '; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } else { echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } } else if ( is_category() ) { // Category ...
wordpress面包屑导航如何设置
显示或返回当前页面的分类目录标题:1、在这里需要用到函数:single_cat_title()对那些显示WordPress标签而非分类目录标题的页面(如"/tag/carceer"),该标签显示或返回标签名称,该标签只能用在WordPress主循环(loop)之外.其基本用法如下: 其默认用法如下:,'display'=> true ); ?> 2、对其参数进行一些必要的说明:$prefix 输出时在标题前的文本信息,默认值:None,类型是字符串,可选$display 显示标题(TRUE)或返回标题以便用在PHP中(FALSE)。
默认值:TRUE,类型是布尔型 可选下面这个例子在分类目录标题后显示“当前分类:”字样:示例如下://output:当前分类目录是wordpress 3、下面这个例子将当前分类目录标题赋值给变量$current_category以用在PHP中.示例代码如下:
...怎么做到一个对排名比较好的网站呢 我现在用的是wordpress程序
有以下几种原因会导致插件效果不显示:1、插件没启用,请登录后台的管理的插件部分,将对应插件启用,如下图:2、没有设置导航栏菜单,当然没有内容可以显示,可以去后台“菜单”设置里将想要显示的菜单添加到菜单栏了里即可。
3、该插件的设置的问题,后台进入插件设置,找到该插件,把导航栏和分类目录都显示选项勾选保存即可。
什么是面包屑导航?
展开全部 面包屑导航作用:1、让用户了解目前所处位置,以及当前页面在整个网站中的位置。
2、体现了网站的架构层级,能够帮助用户快速学习和了解网站内容和组织方式.3、提供返回各个层级的快速入口,方便用户操作。
4、Google已经将面包屑导航整合到搜索结果里面,因此优化面包屑导航每个层级的名称,尽量使用关键字,可以达到SEO优化的效果。
面包屑导航的注意事项:1、对于一个网站来说,内部链接的结构搭建非常重要。
所以面包屑导航应该显示网站的层次,而不是浏览历史。
除了层次以外,面包屑导航还可能显示的是属性标签。
2、面包屑导航的链接和别的一样,要使用文字,不要使用图片或JS。
3、面包屑中尽量出现关键字,可以把“首页”这一类词换成网站名称,要注重细节。
面包屑导航在SEO中虽然不是最主要的,但也有它的作用,做SEO就是做细节,seo优化的重点在于细节,细节决定成败。
...
wordpress的导航条“首页”怎么修改成“主页”
具体更改步骤如下:1. 登录使用wordpress建站的后台,进入后台页面。
2. 点击右侧外观中的菜单。
如下图:3. 将导航标签的首页更改为主页,点击下方的保存菜单即可。
如下图:
转载请注明出处51数据库 » wordpress面包屑导航插件