【问题标题】:Joomla 3 menu active state not workingJoomla 3菜单活动状态不起作用
【发布时间】:2014-03-01 20:35:22
【问题描述】:

我对 joomla 3 有疑问。

我使用自定义模板制作菜单位于/templates/mytemplate/html/mod_menu/mainmenu.php

但是当我点击菜单中的任何链接时,“活动”的数组索引总是为假。

例如当前页面为http://localhost/about.html

并且在数组中的“活动”索引是空的

[1] => stdClass Object
        (
            [id] => 102
            [menutype] => mainmenu
            [title] => О проекте
            [alias] => about
            [note] => 
            [route] => about
            [link] => index.php?option=com_content&view=article&id=1
            [type] => component
            [level] => 1
            [language] => *
            [browserNav] => 0
            [access] => 1
            [params] => JRegistry Object
                (
                    [data:protected] => stdClass Object
                        (
                            [show_title] => 
                            [link_titles] => 
                            [show_intro] => 
                            [info_block_position] => 
                            [show_category] => 
                            [link_category] => 
                            [show_parent_category] => 
                            [link_parent_category] => 
                            [show_author] => 
                            [link_author] => 
                            [show_create_date] => 
                            [show_modify_date] => 
                            [show_publish_date] => 
                            [show_item_navigation] => 
                            [show_vote] => 
                            [show_tags] => 
                            [show_icons] => 
                            [show_print_icon] => 
                            [show_email_icon] => 
                            [show_hits] => 
                            [show_noauth] => 
                            [urls_position] => 
                            [menu-anchor_title] => 
                            [menu-anchor_css] => 
                            [menu_image] => 
                            [menu_text] => 1
                            [page_title] => 
                            [show_page_heading] => 0
                            [page_heading] => 
                            [pageclass_sfx] => 
                            [menu-meta_description] => 
                            [menu-meta_keywords] => 
                            [robots] => 
                            [secure] => 0
                        )

                )

            [home] => 0
            [img] => 
            [template_style_id] => 0
            [component_id] => 22
            [parent_id] => 1
            [component] => com_content
            [tree] => Array
                (
                    [0] => 102
                )

            [query] => Array
                (
                    [option] => com_content
                    [view] => article
                    [id] => 1
                )

            [deeper] => 
            [shallower] => 
            [level_diff] => 0
            [parent] => 
this empty  [active] =>
            [flink] => /about.html
            [anchor_css] => 
            [anchor_title] => 
            [menu_image] => 
        )

【问题讨论】:

  • 你能提供/templates/mytemplate/html/mod_menu/mainmenu.php的代码吗?

标签: php joomla


【解决方案1】:

从基本mod_menu 文件的外观来看,加载菜单的助手始终将 active 属性设置为 false,而是使用自己的检查来查看处于活动状态的内容。即,基础mod_menu.php 文件设置这些值:

$list       = ModMenuHelper::getList($params);
$base       = ModMenuHelper::getBase($params);
$active     = ModMenuHelper::getActive($params);
$active_id  = $active->id;
$path       = $base->tree;

所以active_id 将包含当前菜单项的ID。因此,如果您想要当前菜单,您可以像这样检查:

foreach ($list as $i => &$item) :
if ($item->id == $active_id) {
        // do something with active item
    }
    ....
}

$list 由主文件设置,因此可以在您的布局文件中访问。

您还可以使用此检查在同一 foreach 循环中检查活动项上方的父项:

if (in_array($item->id, $path)) {}

从技术上讲,如果需要,您可以运行第一个 foreach 循环并将 $item->active 设置为 true。然而,那时你可能已经对这个项目做你想做的事了!

【讨论】:

  • 如果这回答了您的问题,请单击答案左侧的复选标记接受答案。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多