继续Drupal分享精神 QQ群:107748121 站长QQ:2275288328 skype: hellodrupal【drupal交流+drupal 建站+theme制作】
登录 注册

drupal 菜单导航加上当前分类,drupal 面包屑breadcrumb重新定义

需求:在导航栏上加上当前位置衔接名称:比如 点击本站 分类 drupal 开发, 然后导航为:
首页 > drupal 开发, 当具体一篇文章,导航则为: 首页 > drupla 开发 > 当前页面网站标题
解决方法:1 使用第三方drupal模块,这个比较简单,
2 自己在drupal 主题 下的template.php里来定义。

这里就使用template.php来定义方法来实现。

先在自己的主题里下面建立一个template.php文件,然后拷贝下面代码

<?php

function phptemplate_breadcrumb($breadcrumb){//重写drupal菜单面包屑
   
if(!empty($breadcrumb)){//如果drrupal面包屑变量不为空
        
       
$breadcrumb[] = l(t(drupal_get_title()),$_REQUEST['q']);//定义一个一个菜单数组。得到当前的标题,$_REQUEST['q'] 衔接地址
        
   
}

    return
"<div class=\"breadcrumb\">".implode(' > ',$breadcrumb)."</div>";//返回面包屑,并且使用>符号把菜单分割开
   
}

function
yourthemenamne_preprocess_page(&$variables){//yourthemenamne 改为自己使用的主题名称
$node = $variables['node'];
       
$terms = $node->taxonomy;
        if(
is_array($terms)){
           
$tax = array();
           
$tax[]= l(t('Home'),'<front>');
            foreach(
$terms as $k=>$term){
               
$tax[] = l(t($term->name),'taxonomy/term/'.$term->tid);//衔接数组,文章所在分类名称
           
}
            
           
$variables['breadcrumb'] = theme('breadcrumb', $tax);// 调用breadcrumb theme
       
}



}
?>

评论

没弄成,原来template里有关于breadcrumb的

没弄成,原来template里有关于breadcrumb的函数,用你的方法的话是要把那个函数删除吗?可是删除了也不行

修改以后要清除缓存。在后台管理 clean cache

修改以后要清除缓存。在后台管理 clean cache 试试。

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.