Drupal 7 开发内部培训资料, 分头诗人

怎么修改drupal菜单的输出代码为自己想要的代码?

赞成!
0
否决!

drupal原菜单的代码是这样的:

<ul id="main-menu-links" class="links clearfix">
<li class="menu-218 first active"><a href="..." title="" class="active">主页</a></li>
<li class="menu-332"><a href="..." title=" ">...</a></li>
<li class="menu-333 active"><a href="..." title="..." class="active">...</a></li>
<li class="menu-331 active"><a href="..." title="..." class="active">...</a></li>
<li class="menu-329"><a href="..." title="...">...</a></li>
<li class="menu-330 active"><a href="..." title="..." class="active">...</a></li>
<li class="menu-334 active-trail last active"><a href="..." title="..." class="active-trail active">...</a></li>
</ul>


要修改哪些文件,里的哪些代码,才能让drupal的输出代码如下:
 

<div id="buttons">
      <a href="index.html" class="but_home"  title=""></a><div class="but_razd"></div>
      <a href="blog.html" class="but" title="">Blog</a><div class="but_razd"></div>
      <a href="gallery.html"  class="but" title="">Gallery</a><div class="but_razd"></div>
      <a href="about_us.html"  class="but" title="">About us</a><div class="but_razd"></div>
      <a href="contact_us.html" class="but" title="">Contact us</a>
    </div>

已经在百度和谷歌都找过了,用过里面说的所有方法都不得,有些说是在template.php里覆写代码,但是我覆写代码后一点变化都没有,难道是覆写后的调用方法错了吗?求解。

5 个回答

赞成!
0
否决!
<?php
function mytheme_menu_tree($variables) {
    if ($GLOBALS['custom_variables']['main-menu']['active'] ) {
        if ($GLOBALS['custom_variables']['main-menu']['level'] == 0) {
            $GLOBALS['custom_variables']['main-menu']['active'] = false;
            return '<ul class="menu" id="top">' . $variables['tree'] . '</ul>';
        } else {
            $GLOBALS['custom_variables']['main-menu']['level'] -= 1;
        }
    } 
    
    return '<ul class="menu">' . $variables['tree'] . '</ul>';
}
?>

在template.php 输入上面代码

赞成!
0
否决!

调用钩子hook_menu_link

<?php
/**
* Add unique class (mlid) to all menu items.
*/
function superseven_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  

$element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];
  if (

$element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
?>
赞成!
0
否决!

在template_preprocess_page()里面调用menu_navigation_links(),

function THEMENAME_preprocess_page(&$variables){
  $variables['custom_menu'] = menu_navigation_links('menu-custom-menu');
}

function THEMENAME_links__menu_custom_menu(&$variables){
 //custom theme function here
}

然后在page.tpl.php加下面这句:

<?php print theme('links__menu_custom_menu', array('links' => $custom_menu, 'attributes' => array('id' => 'custom-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Custom menu'))); ?>
赞成!
0
否决!

三个方法都试过了,第一第二个方法没起作用啊,是不是修改了之后要在page.tpl.php调用什么才可以的,要怎样调用才可以

 

第三种方法用了之后出现

Parse error: syntax error, unexpected '?> ', expecting ')' in D:\xampp\htdocs\fr\sites\all\themes\Xfang\templates\page.tpl.php on line 52

 

赞成!
0
否决!

我的page.tpl.php里面是这样写的,对吗?

<?php if ($main_menu): ?>
<div id="buttons">
  <?php print $main_menu ?>
  </div>
   <?php endif; ?>