简体   繁体   English

在Joomla中将自定义元素添加到主菜单项

[英]Add custom element to home menu item in Joomla

What i'm trying to do is quite simple as concept, but i'm not that good with php and the joomla framework. 我想做的是一个非常简单的概念,但是对于php和joomla框架我不是那么好。 Currently the home menu-item is generated like this: 当前, 主菜单项是这样生成的:

<li class="item-101 current active">
  <a class="hide-text" href="#some-link">Home</a>
</li>

What i'd like to achieve is to insert an <i> element inside only the home menu-item, something like this: 我想要实现的是主菜单项内插入<i>元素,如下所示:

<li class="item-101 current active">
  <a class="hide-text" href="#some-link"><i class="icon-home"></i>Home</a>
</li>

How can i achieve this? 我怎样才能做到这一点? I'm using Joomla! 我正在使用Joomla! 2.5 atm 2.5个大气压

I guess it's possible do something like "if this menu-item is the home link then add this code inside the <a> tags" but i really don't know how to do it, my php is not strong enough :P 我想有可能做类似“如果此菜单项是首页链接,然后在<a>标记内添加此代码”之类的事情,但是我真的不知道该怎么办,我的php不够强大:P

Note: 注意:
i'm doing this to achieve a simple home-icon instead of the litteral home menu-item. 我这样做是为了实现一个简单的首页图标,而不是乱扔垃圾的首页菜单项。
As the classes syntax could suggest, i'm using the twitter bootstrap css-framework, but i've implemented the Icomoon font-set (as in joomla 3.0) instead of the tbs Glyph-icons sprites images. 正如类语法所暗示的那样,我使用的是twitter bootstrap css-framework,但是我实现了Icomoon字体集(如joomla 3.0),而不是tbs字形图标精灵图像。
Unfortunately, using font-based icons, text rules are applied to the icons also, and that is the reason i'm trying to insert a custom element inside the <a> tag, so that i can override the hide-text class hiding the home-icon. 不幸的是,使用基于字体的图标,文本规则也应用于图标,这就是我试图在<a>标记内插入自定义元素的原因,以便我可以覆盖hide-texthide-text类。主页图标。

Thanks for any suggestion! 感谢您的任何建议!

Have a look in the template file of the menu module. 看看菜单模块的模板文件。

/modules/mod_menu/tmpl/default.php /modules/mod_menu/tmpl/default.php

The template builds the HTML for the menu module. 该模板为菜单模块构建HTML。

I just checked how it works in Joomla 2.5, and in the /modules/mod_menu/tmpl/default.php template the list is build. 我刚刚检查了它在Joomla 2.5中的工作方式,并在/modules/mod_menu/tmpl/default.php模板中构建了列表。 If you want to add to only the home link you'll have to add a little bit of code. 如果只想添加到主页链接,则必须添加一些代码。 Something like this : 像这样的东西:

if($item->home == '1'){ $item->title = '<i class="icon-home"></i>' . $item->title; };

Insert this just under the foreach loop and have a go, it should look something like this : 将其插入到foreach循环下并开始执行,它应该类似于以下内容:

foreach ($list as $i => &$item) :
    // THIS ADDS THE <i> to only the HOME LINK
    if($item->home == '1'){ $item->title = '<i class="icon-home"></i>' . $item->title; }; 

    $class = 'item-'.$item->id;
    if ($item->id == $active_id) {
        $class .= ' current';
    }

Good Luck ;) 祝好运 ;)

I have been following this guide as well, (Thanks Gruber and Mark Vink) but using the glyphicons instead of IcoMoon. 我也一直在遵循本指南(感谢Gruber和Mark Vink),但是使用字形图标而不是IcoMoon。 I found there to be a syntax error in the example above. 我发现上面的示例中存在语法错误。 The version hat worked for me was 对我有用的帽子是

foreach ($list as $i => &$item) { 

if($item->home == '1')$item->title = '<span class="glyphicon glyphicon-home" aria-hidden="true"></span>' .$item->title; 
$class = 'item-' . $item->id

etc... 等等...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM