十一月 26

【Drupal】如何使 breadcrumb 在仅包含 home 时隐藏

在 Drupal 模板开发中会用到 breadcrumb 面包屑,其功能是输出当前页面与整个站点的层次结构关系,虽然在目前的一些网站中其功能性与重要性逐渐淡化,但在以往及所有以内容为主的网站中“面包屑”显得尤为重要。但我们发现在 Drupal 默认的情况下,绝大多数页面的 breadcrumb 只会显示一个“首页”链接,这个时候其实可以隐藏掉该区域,只需要在模板中判断 breadcrumb 数组中的单元数目是否多于一个即可。

具体代码放入 template.php 中并修改 theme 为你的主题名称:

1
2
3
4
5
6
 
function theme_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb) && count($breadcrumb) > 1) {
    return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
  }
}

其实就是覆写了 Drupal 原来的面包屑函数(即 theme_breadcrumb 在 theme.inc 中)多添加了一个判断条件 count($breadcrumb) 判断是否多于一个单元,如果仅有一个单元则不返回任何结果。

分享到:

本文网址:http://anyLiv.com/blog/1158 转载需注明出处!
This site is licensed under a Creative Commons BY-NC-SA 3.0 License.
本站使用 创作共用版权协议 转载本站内容也必须遵循"署名-非商业性使用-相同方式共享"的共同创作协议。

发表评论:

NOTICE: You should type some Chinese Word in your comment to pass the spam-check, thanks !

小提示:请务必填写正确的邮箱地址(推荐 QQ 邮箱)以便能及时收到我的回复,另未包含中文的评论将被过滤!


谷歌广告 gAdSense


Themed by anyLiv. Copyright © 2010. Some right reserved.