简体   繁体   English

在Joomla菜单项上创建子行

[英]Creating sublines on Joomla menu items

In my toplevel menu items, I would like to make a subline for each item. 在我的顶级菜单项中,我想为每个项创建一个子行。 I don't think it's possible to do by default, byt YooTheme has done it in many of their templates. 我认为默认情况下不可能这样做,byy YooTheme在他们的许多模板中都做到了。

The menu output look like this 菜单输出如下所示

<div class="moduletable_menu">
<ul id="mainmenu" class="menu">
    <li class="active item1" id="current">
        <a href="URL_HIDDEN">
            <span>Services</span>
        </a>
    </li>
</ul>

This basically outputs a one line menu item like so: 基本上,这将输出一个单行菜单项,如下所示:

Services 服务

What I would like to do is have a menu item like this: 我想做的是有一个像这样的菜单项:

Services 服务
Service x, Service y, Service z 服务x,服务y,服务z

For reference, have a look at the main menu on the YooTheme demo page . 作为参考,请查看YooTheme演示页面上的主菜单。

The way YooTheme does this, is using two pipes (||) as a linebreak, so in the Joomla backend you type "Services||Service x, Service y, Service z" as the menu title, and then there must be some fancy javascript that breaks this title into two spans, ready to be styled using css. YooTheme实现此目的的方式是使用两个管道(||)作为换行符,因此在Joomla后端中,键入“ Services || Service x,Service y,Service z”作为菜单标题,然后一定要花哨一些javascript,可将此标题分为两个范围,可以使用CSS设置样式。

Does anyone know of an easy way to code this? 有谁知道一种简单的编码方法?

Please note that I am looking to build this feature into a custom template (ie. non-yootheme). 请注意,我正在寻求将此功能构建到自定义模板中(即非Yothetheme)。

Also note that I am not using MooTools, but Jquery instead. 另请注意,我没有使用MooTools,而是使用了Jquery。

This worked for Joomla 3.2 这适用于Joomla 3.2

Create an override in your template: For example: templates/beez_20/html/mod_menu/default_component.php and use the following code: 在模板中创建替代:例如:templates / beez_20 / html / mod_menu / default_component.php并使用以下代码:

// No direct access.
defined('_JEXEC') or die;

// Note. It is important to remove spaces between elements.
$class = $item->anchor_css ? 'class="'.$item->anchor_css.'" ' : '';
$title = $item->anchor_title ? 'title="'.$item->anchor_title.'" ' : '';

if ($item->menu_image) {
      $item->params->get('menu_text', 1 ) ? 
      $linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" /><span class="image-title">'.$item->title.'</span> ' :
      $linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" />';
} 
else { $linktype = $item->title;
}

$ta=explode('~',$linktype);  /////////////////////////// 3 new lines here
$linktype=$ta[0];
$subtitle=$ta[1];

switch ($item->browserNav) :
   default:
   case 0:
?><a <?php echo $class; ?>href="<?php echo $item->flink; ?>" <?php echo $title; ?>><?php echo $linktype; ?></a><?php
      break;
   case 1:
      // _blank
?><a <?php echo $class; ?>href="<?php echo $item->flink; ?>" target="_blank" <?php echo $title; ?>><?php echo $linktype; ?></a><?php
      break;
   case 2:
   // window.open
?><a <?php echo $class; ?>href="<?php echo $item->flink; ?>" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false;" <?php echo $title; ?>><?php echo $linktype; ?></a>
<?php
      break;
endswitch;

if ($subtitle!=null) {    /////////////////////////// 4 new lines here
  echo '<div style="margin-top:0px;margin-bottom:10px;margin-left:15px;font-style:italic;"><small>'.$subtitle.'</small></div>';
}

Write menu text as header~subheader 将菜单文本写为header〜subheader

I finally figured this out, and thought I'd share it, if anyone else needs this. 我终于想通了,并认为如果有人需要它,我会分享的。

First of all you need to create a template override for the mod_mainmenu. 首先,您需要为mod_mainmenu创建一个模板替代

Next, open up the override file (default.php) and insert this peice of code after the last IF: 接下来,打开替代文件(default.php),并在最后一个IF之后插入以下代码:

// add title & sub span
if (isset($node->_children[0]) && isset($node->_children[0]->span[0])) {
    $title = $node->_children[0]->span[0];
    $split = explode('//', $title->data(), 2);
    if (count($split) == 2) {
        $span =& $node->_children[0]->span[0]->addChild('span', array('class' => 'title'));
        $span->setData(trim($split[0]));
        $span =& $node->_children[0]->span[0]->addChild('span', array('class' => 'sub'));
        $span->setData(trim($split[1]));
    }
}

Now you can type a subline in your menuitem title field, you just need to put // as a delimiter. 现在,您可以在menuitem标题字段中键入一个子行,只需将//作为分隔符即可。 Example: Lorem Ipsum//Dolor sit amet 示例:Lorem Ipsum // Dolor坐在amet

The outputted html looks like this: 输出的html看起来像这样:

<li class="parent item2">
<a href="YOURURL">
    <span>
        <span class="title">Lorem Ipsum</span>
        <span class="sub">Dolor sit amet</span>
    </span>
</a>

This can now be styled with css. 现在可以使用CSS设置样式。

Happy days! 快乐的时光! :) :)

TIP! 小费! You can choose whatever delimiter you like, just make sure to change it in the default.php. 您可以选择任何喜欢的定界符,只需确保在default.php中进行更改即可。 I went with the double slash, as it's easy to type. 我使用双斜杠,因为它很容易键入。

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

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