简体   繁体   English

Joomla菜单拆分PHP

[英]Joomla Menu Split PHP

I am currently trying to override a joomla menu so that it looks like: 我目前正在尝试覆盖joomla菜单,使其看起来像:

item | 项目| item | 项目| item | 项目| item LOGO item | LOGO项目| item | 项目| item |item 项目|项目

So basically i am trying to split the menu in half into two <ul> 's I got is working but unfortunately i magically got it broken... 所以基本上我想将菜单分成两半<ul>我正在工作,但不幸的是我神奇地把它弄坏了...

Here's the unedited code for the menu: 这是菜单的未编辑代码:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_menu
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Note. It is important to remove spaces between elements.
?>
<?php // The menu class is deprecated. Use nav instead. ?>
<ul class="nav menu<?php echo $class_sfx;?>"<?php
    $tag = '';
    if ($params->get('tag_id') != null)
    {
        $tag = $params->get('tag_id').'';
        echo ' id="'.$tag.'"';
    }
?>>
<?php
foreach ($list as $i => &$item) :
    $class = 'item-'.$item->id;
    if ($item->id == $active_id)
    {
        $class .= ' current';
    }

    if (in_array($item->id, $path))
    {
        $class .= ' active';
    }
    elseif ($item->type == 'alias')
    {
        $aliasToId = $item->params->get('aliasoptions');
        if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
        {
            $class .= ' active';
        }
        elseif (in_array($aliasToId, $path))
        {
            $class .= ' alias-parent-active';
        }
    }

    if ($item->type == 'separator')
    {
        $class .= ' divider';
    }

    if ($item->deeper)
    {
        $class .= ' deeper';
    }

    if ($item->parent)
    {
        $class .= ' parent';
    }

    if (!empty($class))
    {
        $class = ' class="'.trim($class) .'"';
    }

    echo '<li'.$class.'>';

    // Render the menu item.
    switch ($item->type) :
        case 'separator':
        case 'url':
        case 'component':
        case 'heading':
            require JModuleHelper::getLayoutPath('mod_menu', 'default_'.$item->type);
            break;

        default:
            require JModuleHelper::getLayoutPath('mod_menu', 'default_url');
            break;
    endswitch;

    // The next item is deeper.
    if ($item->deeper)
    {
        echo '<ul class="nav-child unstyled small">';
    }
    // The next item is shallower.
    elseif ($item->shallower)
    {
        echo '</li>';
        echo str_repeat('</ul></li>', $item->level_diff);
    }
    // The next item is on the same level.
    else {
        echo '</li>';
    }
endforeach;
?></ul>

And Here's the Code I edited and got it working until now: 这是我编辑过的代码,直到现在一直有效:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_menu
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Note. It is important to remove spaces between elements.
?>
<?php // The menu class is deprecated. Use nav instead. ?>
<?php if($class_sfx == " menu-logo"): ?>
<ul class="nav menu<?php echo $class_sfx;?> span4 pull-left menu-left"<?php
    $tag = '';
    if ($params->get('tag_id') != null)
    {
        $tag = $params->get('tag_id').'';
        echo ' id="'.$tag.'"';
    }
endif;
?>
<?php if($class_sfx != " menu-logo"): ?>
<ul class="nav menu<?php echo $class_sfx;?>"<?php
    $tag = '';
    if ($params->get('tag_id') != null)
    {
        $tag = $params->get('tag_id').'';
        echo ' id="'.$tag.'"';
    }
endif;
?>>
<?php 
$counter = 0;
foreach ($list as $i => &$item) :
    $class = 'item-'.$item->id;
     if($item->params->get('menu-anchor_css') == "dropdown-toggle") {
    $class = 'dropdown item-'.$item->id;
    } else {
    $class = 'item-'.$item->id;
    }

    if (in_array($item->id, $path))
    {
        $class .= ' active';
    }
    elseif ($item->type == 'alias')
    {
        $aliasToId = $item->params->get('aliasoptions');
        if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
        {
            $class .= ' active';
        }
        elseif (in_array($aliasToId, $path))
        {
            $class .= ' alias-parent-active';
        }
    }

    if ($item->type == 'separator')
    {
        $class .= ' divider';
    }

    if ($item->deeper)
    {
        $class .= 'dropdown-menu deeper';
    }

    if ($item->parent)
    {
        $class .= ' parent dropdown';
    }

    if (!empty($class))
    {
        $class = ' class="'.trim($class) .'"';
    }

    echo '<li'.$class.'>';

    // Render the menu item.
    switch ($item->type) :
        case 'separator':
        case 'url':
        case 'component':
        case 'heading':
            require JModuleHelper::getLayoutPath('mod_menu', 'default_'.$item->type);
            break;

        default:
            require JModuleHelper::getLayoutPath('mod_menu', 'default_url');
            break;
    endswitch;

    // The next item is deeper.
    if ($item->deeper)
    {
        echo '<ul class="nav-child dropdown-menu">';
    }
    // The next item is shallower.
    elseif ($item->shallower)
    {
        echo '</li>';
        echo str_repeat('</ul></li>', $item->level_diff);
    }
    // The next item is on the same level.
    else {
        $counter++;
        echo '</li>';
        if($counter == 4 && $class_sfx == " menu-logo"){
            echo "</ul>";
            echo "<div class='logo span4 hidden-phone'><img src='".JURI::base( true )."logo.png' /></div>";
            echo "<ul class='nav menu menu-right pull-right'>";
        }
    }
endforeach;
?></ul>
<div class='clearfix'></div>

Sorry I know its ALOT of code, but cant really leave things out... any help greatly appreciated. 抱歉,我知道很多代码,但是不能把事情遗漏了……任何帮助都将不胜感激。

Please not i need to use a solution based on the solution i came up with.. I have just done way to much CSS on the method i provided to revert right now... 请不要基于我想出的解决方案使用一个解决方案。.我刚刚在我现在提供的要恢复的方法上做了很多CSS的方法...

you'd better use Joomla option to achieve this, then you don't need to test $counter. 您最好使用Joomla选项来实现此目的,然后无需测试$ counter。 In menu manager, edit your menu item, then in link type options select and add a link image. 在菜单管理器中,编辑菜单项,然后在链接类型选项中选择并添加链接图像。 Then in your code in for each loop : 然后在每个循环的代码中:

   $spanImg ='';
    if ($item->menu_image) {
      $spanImg = '<div class="logo span4 hidden-phone"><img src="'.$item->menu_image.'" /></div>';
    }
    ...
       // The next item is deeper.
        if ($item->deeper)
        {
            echo '<ul class="nav-child dropdown-menu">';
        }
    ...
      // The next item is on the same level.
        else {
            echo $spanImg.'</li>';
        }

otherwise as you call default_url.php you can find this piece of code in this file and it should also work. 否则,当您调用default_url.php时,您可以在此文件中找到这段代码,它也应该起作用。

Use $item->level instead of counting everything with $counter only count items that have a level lower then 2. See code below: 使用$item->level而不是使用$counter来计数所有内容,只计数级别低于2的项目。请参见下面的代码:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_menu
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Note. It is important to remove spaces between elements.
?>
<?php // The menu class is deprecated. Use nav instead. ?>
<?php if($class_sfx == " menu-logo"): ?>
<ul class="nav menu<?php echo $class_sfx;?> span4 pull-left menu-left"<?php
    $tag = '';
    if ($params->get('tag_id') != null)
    {
        $tag = $params->get('tag_id').'';
        echo ' id="'.$tag.'"';
    }
endif;
?>
<?php if($class_sfx != " menu-logo"): ?>
<ul class="nav menu<?php echo $class_sfx;?>"<?php
    $tag = '';
    if ($params->get('tag_id') != null)
    {
        $tag = $params->get('tag_id').'';
        echo ' id="'.$tag.'"';
    }
endif;
?>>
<?php 
foreach ($list as $i => &$item) :
    if($item->level < 2):
        $counter += count($item);
    endif;

    $class = 'item-'.$item->id;
     if($item->params->get('menu-anchor_css') == "dropdown-toggle") {
    $class = 'dropdown item-'.$item->id;
    } else {
    $class = 'item-'.$item->id;
    }

    if (in_array($item->id, $path))
    {
        $class .= ' active';
    }
    elseif ($item->type == 'alias')
    {
        $aliasToId = $item->params->get('aliasoptions');
        if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
        {
            $class .= ' active';
        }
        elseif (in_array($aliasToId, $path))
        {
            $class .= ' alias-parent-active';
        }
    }

    if ($item->type == 'separator')
    {
        $class .= ' divider';
    }

    if ($item->deeper)
    {
        $class .= 'dropdown-menu deeper';
    }

    if ($item->parent)
    {
        $class .= ' parent dropdown';
    }

    if (!empty($class))
    {
        $class = ' class="'.trim($class) .'"';
    }

    echo '<li'.$class.'>';

    // Render the menu item.
    switch ($item->type) :
        case 'separator':
        case 'url':
        case 'component':
        case 'heading':
            require JModuleHelper::getLayoutPath('mod_menu', 'default_'.$item->type);
            break;

        default:
            require JModuleHelper::getLayoutPath('mod_menu', 'default_url');
            break;
    endswitch;

    // The next item is deeper.
    if ($item->deeper)
    {
        echo '<ul class="nav-child dropdown-menu">';
    }
    // The next item is shallower.
    elseif ($item->shallower)
    {
        echo '</li>';
        echo str_repeat('</ul></li>', $item->level_diff);
    }
    // The next item is on the same level.
    else {
        echo '</li>';
    }
    if($counter == 4 && $class_sfx == " menu-logo"){
            echo "</ul>";
            echo "<div class='logo span4 hidden-phone'><img src='".JURI::base( true )."logo.png' /></div>";
            echo "<ul class='nav menu menu-right pull-right'>";
        }
endforeach;
?></ul>
<div class='clearfix'></div>

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

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