【问题标题】:Joomla 2.5 add parent alias as body classJoomla 2.5 添加父别名作为正文类
【发布时间】:2012-04-06 13:38:48
【问题描述】:

自 Joomla 1.5 以来代码已更改,这是我的尝试:

在头脑中

<?php $parent = JFactory::getApplication()->getMenu()->getParent(); ?>  

在正文标签上

<body class="<?php echo $parent->alias; ?>">

知道出了什么问题...?谢谢

【问题讨论】:

    标签: php joomla joomla2.5


    【解决方案1】:

    找到你的帖子然后找到这个,我认为它完美地回答了它,至少它对我有用

    http://www.joomla4web.com/blog/finding-the-top-menu.html

     $menu = JFactory::getApplication()->getMenu();
    $active = $menu->getActive();
    $top = $active ? $menu->getItem($active->tree[0]) : null;
    echo $top->alias;
    

    【讨论】:

      【解决方案2】:

      我正在使用:

      <?php
      $menu =& JSite::getMenu();
      $active = $menu->getActive();
      $class = extractpath($active->route);
      function extractpath($string){
      preg_match('/^[a-zA-Z0-9\-_]+/',$string,$m);
      return $m[0];
      }
      
      ?>
      <body<?php if ($class) echo ' class="' . $class . '"'; ?>>
      

      【讨论】:

        猜你喜欢
        • 2023-03-16
        • 1970-01-01
        • 2014-03-11
        • 1970-01-01
        • 1970-01-01
        • 2012-06-30
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多