Joomla:如何显示子菜单项

时间:2022-08-16 19:30:04

I created a website using Joomla! 3.4.1. It has some categories and the main menu looks like this:

我使用Joomla创建了一个网站! 3.4.1。它有一些类别,主菜单如下所示:

  • Home
    • Main Category
      • Category 1
        • Category 1.1
          • Category 1.1.1
          • Category 1.1.2
          • Category 1.1.3
        • 类别1.1类别1.1.1类别1.1.2类别1.1.3

        • Category 1.2
        • Category 1.3
      • 类别1类别1.1类别1.1.1类别1.1.2类别1.1.3类别1.2类别1.3

      • Category 2
        • Category 2.1
        • Category 2.2
      • 第2类第2.1类第2.2类

    • 主要类别类别1类别1.1类别1.1.1类别1.1.2类别1.1.3类别1.2类别1.3类别2类别2.1类别2.2

  • 主要类别类别1类别1.1类别1.1.1类别1.1.2类别1.1.3类别1.2类别1.3类别2类别2.1类别2.2

I decided (I'm not sure if it was the best decision) to create the complete website structure in the main menu.

我决定(我不确定这是否是最好的决定)在主菜单中创建完整的网站结构。

Now, in the "Category 1" page, I would like to have a menu showing some selected sub-menu items, for example:

现在,在“类别1”页面中,我希望有一个菜单显示一些选定的子菜单项,例如:

Category 1 Menu:

第1类菜单:

  • Category 1.1
  • Category 1.3

In order to achieve this, I decided to create a new menu called "Category 1 Menu" with menu item aliases (to avoid creating new URLs).

为了实现这一点,我决定创建一个名为“Category 1 Menu”的新菜单,其中包含菜单项别名(以避免创建新的URL)。

Until now everything was ok, the problem is now I want to display Category 1.1 sub-items, but I just want to display the children of Category 1.1 when Category 1.1 is selected. Something like this:

到目前为止一切正常,问题是现在我想显示类别1.1子项,但我只想在选择类别1.1时显示类别1.1的子项。像这样的东西:

Category 1

  • Category 1.1
  • Category 1.3

And if I click on "Category 1.1" its items should expand like this:

如果我点击“类别1.1”,它的项目应该像这样展开:

Category 1

  • Category 1.1
    • Category 1.1.1
    • Category 1.1.2
    • Category 1.1.3
  • 类别1.1类别1.1.1类别1.1.2类别1.1.3

  • Category 1.3

Remember, all these items are menu item aliases.

请记住,所有这些项目都是菜单项别名。

I know how to do it without usign menu item aliases but in this case, I think that I need to use menu item aliases, otherwise I won't have a complete "tree" structure in the breadcrumbs.

我知道如何在没有菜单项别名的情况下这样做,但在这种情况下,我认为我需要使用菜单项别名,否则我将不会在面包屑中有一个完整的“树”结构。

What can I do?

我能做什么?

Thanks in advance!

提前致谢!

1 个解决方案

#1


if you don't wanna use aliases you can easily create a module or search for one in JED. Basically code for sub menu is like this:

如果你不想使用别名,你可以轻松地创建一个模块或在JED中搜索一个模块。基本上子菜单的代码是这样的:

$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$childs = $menu->getItems('parent_id', $active->id);
//now if childs are empty yoy don't have a submenu
if( !empty($childs) )
{
    //show menu using foreach $childs as $child and creating friendly url using JRoute
}

#1


if you don't wanna use aliases you can easily create a module or search for one in JED. Basically code for sub menu is like this:

如果你不想使用别名,你可以轻松地创建一个模块或在JED中搜索一个模块。基本上子菜单的代码是这样的:

$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$childs = $menu->getItems('parent_id', $active->id);
//now if childs are empty yoy don't have a submenu
if( !empty($childs) )
{
    //show menu using foreach $childs as $child and creating friendly url using JRoute
}