首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress面包屑问题

Wordpress面包屑问题
EN

Stack Overflow用户
提问于 2014-03-21 08:54:48
回答 1查看 2.4K关注 0票数 0

我的网站上有个面包屑不能正常工作。当我去买像这样的产品

Equipment» Products» Railing» Heavy Railing» Waterproof» Superrail 2000

它给我看了这个面包屑,就像它应该的那样。然而,当我通过“不防水”而不是“防水”获得相同的产品时,它向我展示了同样的面包屑(非常简单,它只遵循一个类别)。

我想在我的面包屑插件的设置中检查这个,但它显示了这样的信息:“您的设置已过时。请立即迁移。”而我的主管建议我不要“迁移”它。

是否有人有使用插件或自定义代码的解决方案,可以处理多个类别?

编辑:

我正在使用WP3.6,这是不允许更新的。URL看起来类似于这个http://www.website.com/product/asl6109t32/,这意味着我不能使用这个URL来生成面包屑。

EN

回答 1

Stack Overflow用户

发布于 2014-03-21 09:11:11

如果可以的话,下面是一些用于创建面包屑导航的漂亮代码片段,将其放在主题的functions.php文件中:

代码语言:javascript
复制
/*********************************************************** 
* wsf_breadcrumbs() - Shows breadcrumbs in template 
***********************************************************/  
function wsf_breadcrumbs( $sep = '/', $label = 'Browsing' ) {  

    global $post, $front_page;  

   // Do not show breadcrumbs on home or front pages.  
   // So we will just return quickly  
   if((is_home() || is_front_page()) && (!$front_page))  
      return;  

    // Create a constant for the separator, with space padding.  
    $SEP = ' ' . $sep . ' ';  

  echo '<div class="breadcrumbs">';  
  echo $label;  
  echo wsf_make_link( home_url(), 'Home', get_bloginfo('name'), true ) . $SEP;  

  if(is_single()) {  
    the_category(', '); echo $SEP;   
  } 
    elseif (is_search()) {
        echo 'Search results - ';
    } 
    elseif (is_404()) { //Wordpress bug
        echo 'Error 404 (Page not found) '; 
    }
    elseif (is_author()) {
        echo 'Articles posted by author ';
    }
    elseif (is_tag()) { 
        echo 'Posts tagged ';
    }
    elseif (is_year()) {
        echo get_the_time('Y');
    }
  elseif (is_month()) {
        echo get_the_time('F').' ('.get_the_time('Y').')';
    }

    elseif (strstr($_SERVER['REQUEST_URI'],"wp-login.php")) {
        echo 'Administration panel';
    }


    elseif(is_page()) {  
        $parent_id = $post->post_parent;  
        $parents = array();  
        while($parent_id) {  
                $page = get_page($parent_id);  
        $parents[]  = wsf_make_link( get_permalink($page->ID), get_the_title($page->ID) ) . $SEP;  
                $parent_id  = $page->post_parent;  
        }  
        $parents = array_reverse($parents);  
    foreach($parents as $parent) {  
       echo $parent;  
    }  
  }  
   // Wordpess function that echoes your post title.  
  the_title();  
  echo '</div>';  
}  
/*------------------------------------------------------*/
/* Create breadcrumb navigation
/*------------------------------------------------------*/
/*********************************************************** 
* Helper Functions for template coding 
***********************************************************/  
function wsf_make_link ( $url, $anchortext, $title=NULL, $nofollow=false ) {  
   if ( $title == null ) $title=$anchortext;  
   $rel = ($nofollow == true) ? ' rel="nofollow"' : $rel = '';   

   $link = sprintf( '<a href="%s" title="%s" %s>%s</a>', $url, $title, $rel, $anchortext );  
   return $link;   
}  

/*------------------------------------------------------*/
/*------------------------------------------------------*/

然后,在您的footer.php文件中,调用如下函数:

代码语言:javascript
复制
<div id="breadcrumb">
 <?php wsf_breadcrumbs('','') ?>  
</div>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22554152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档