Drupal 7 自定义主菜单
我迫切需要帮助。我正在尝试(仅)在 Drupal 7 中自定义主菜单,以便它满足我的 blueprintcss 需求。我试图在文档中找到答案,但没有简单的示例,这使得它有点困难。
基本要求是其他菜单(导航等)不受主菜单样式的影响。
我的 page.tpl.php 包含以下代码:
<?php if ($main_menu): ?>
<div class="span-9" id="topmenu">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'inline', 'clearfix'),
),
)); ?>
</div>
<?php endif; ?>
输出显示:
<div class="span-9" id="topmenu">
<ul id="main-menu" class="links inline clearfix">
<li class="menu-151 first"><a href="/drupal/" title="">Home</a></li>
<li class="menu-152"><a href="/drupal/" title="">Contact Us</a></li>
<li class="menu-153 last"><a href="/drupal/" title="">About Us</a></li>
</ul>
</div>
而所需的输出应该是这样的:
<div class="span-9" id="topmenu">
<div class="span-3 menu-151"><a href="/drupal/" title="">Home</a></div>
<div class="span-3 menu-152"><a href="/drupal/" title="">Contact Us</a></div>
<div class="span-3 menu-153 last"><a href="/drupal/" title="">About Us</a></div>
</div>
I desperately need help. I am trying to customize main menu (only) in Drupal 7 so that it suits my blueprintcss needs. I tried to find the answer in the documentation, but there is no straightforward example for this, which makes it a bit difficult.
Basic requirement is to have other menus (navigation etc) not affected by the main menu styling.
My page.tpl.php includes this code:
<?php if ($main_menu): ?>
<div class="span-9" id="topmenu">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'inline', 'clearfix'),
),
)); ?>
</div>
<?php endif; ?>
The output shows:
<div class="span-9" id="topmenu">
<ul id="main-menu" class="links inline clearfix">
<li class="menu-151 first"><a href="/drupal/" title="">Home</a></li>
<li class="menu-152"><a href="/drupal/" title="">Contact Us</a></li>
<li class="menu-153 last"><a href="/drupal/" title="">About Us</a></li>
</ul>
</div>
Whereas the desired output should be something like this:
<div class="span-9" id="topmenu">
<div class="span-3 menu-151"><a href="/drupal/" title="">Home</a></div>
<div class="span-3 menu-152"><a href="/drupal/" title="">Contact Us</a></div>
<div class="span-3 menu-153 last"><a href="/drupal/" title="">About Us</a></div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以重写主题函数来修改生成的标记。
要实现此目的:
theme_links__system_main_menu
)。在
phptemplate
或自定义模块中完成)divs
而不是ul li
请参阅官方 Drupal 文档:覆盖主题输出“如何以 Drupal 方式更改 HTML”部分
You can override the theme function to modify the generated markup.
To achieve this :
theme_links__system_main_menu
).be done in
phptemplate
or custom module)divs
instead oful li
See the offical Drupal documentation : Overriding themable output Section "How to change HTML the Drupal way"