wordpress面包屑导航制作的方法和显示效果

优采云 发布时间: 2021-07-16 03:26

  wordpress面包屑导航制作的方法和显示效果

  Breadcrumbs 是网页导航设计中的标准设计模式,在网站browsing 中非常有用。

  在wordpress主题开发过程中,经常需要在文章页面或者独立页面添加面包屑导航来优化网站得SEO。很多SEOer都同意在网站添加面包屑导航有助于提升访问者体验和搜索引擎优化,所以大部分网站都设计了面包屑导航。

  先看显示:

  

  wordpress面包屑导航的*敏*感*词*法如下:

  1、在你当前主题的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 "";

}

}

  2、在需要使用的面包屑导航页面添加如下调用代码:

  3.在主题的css样式文件中添加如下样式代码:

  

ul.breadcrumbs {

list-style: none;

padding: 0;

margin: 0;

font-size:12px;

}

ul.breadcrumbs li {

float: left;

margin: 0 5px 0 0;

padding: 0;

}

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线