Drupal - 将 li 中的自定义 html 添加到菜单 ul?
有没有办法编写一些 html(就像您可能在块中一样),并使该 html 显示为菜单项?
我的情况是,我想要一些不是链接的文本来表示“关注我们:”,然后我想要 2 个图像,它们都是 Twitter 和 Facebook 的链接。
菜单 html 无法执行此操作,因为它要求您编写的任何 html 都成为链接的一部分,并且与该菜单条目的链接相同。 http://drupal.org/project/menu_html
我真的希望我添加的 html 位于菜单中列表。 谢谢
更新 代码在注释中不能很好地工作,所以我在这里添加它。此链接似乎最接近您的建议:
http://api.drupal.org/api/drupal/includes--menu.inc/function/theme_menu_item/6
所以我将其添加到我的 template.php 中:
function localhost_petitpim_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' ' . $extra_class;
}
if ($in_active_trail) {
$class .= 'active-trail myactive';
}
return '<li class="' . $class . '">' . $link . $menu . "</li>\n";
}
我所做的就是添加一类 ' myactive' 这样我就可以看看它是否有效。我的主题名称是“localhost_petitpim”。我刷新了缓存。我的主题设置为“在每个页面上重建主题注册表”。我看不到正在应用的新课程。我做错了什么吗? 谢谢
Is there any way to write some html (as you might in a block), and have that html appear as a menu item?
My situation is that I want some text that is not a link to say 'Follow us on:', and then I want 2 images which are both links to twitter and facebook.
Menu html cant do this as it requires any html you write to be part of a link, and to be the same link for that menu entry.
http://drupal.org/project/menu_html
I really want the html I add to be within the menu list.
Thanks
UPDATE
Code doesn't work well in the comments so im adding it here. This link seemed to be the closest to what you were suggesting:
http://api.drupal.org/api/drupal/includes--menu.inc/function/theme_menu_item/6
So I added this to my template.php:
function localhost_petitpim_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' ' . $extra_class;
}
if ($in_active_trail) {
$class .= 'active-trail myactive';
}
return '<li class="' . $class . '">' . $link . $menu . "</li>\n";
}
All ive done is add a class of 'myactive' so I can see if its working. My theme name is 'localhost_petitpim'. Ive refreshed the cache. My theme is set to 'Rebuild theme registry on every page.' I cant see the new class being applied. Have I done something wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地在 tpl.php 文件中硬编码文本和链接图像。
只需将带有所需代码的 html 块放入菜单后的 tpl.php 中即可。围绕菜单和菜单制作新的包装纸如果主题的当前 html 结构不支持此解决方案,则阻止。块应该向右浮动或内联显示,具体取决于主题的 HTML+CSS。
希望这有帮助。
You can simply hard-code text and linked images in your tpl.php file(s).
Just put html block with desired code in tpl.php after menu. Make new wraper around menu & block if current html structure of your theme is not supporting this solution. Block should be floated right or displayed inline depending on HTML+CSS of your theme.
Hope this helps.
这不是一个很好的解决方案,但它确实有效。
template.php
文件中实现phptemplate_menu_link
来覆盖theme_menu_link
方法。Not a nice solution, but it works.
theme_menu_link
method by implementingphptemplate_menu_link
in yourtemplate.php
file.