Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Joomla菜单分割PHP_Php_Joomla_Foreach - Fatal编程技术网

Joomla菜单分割PHP

Joomla菜单分割PHP,php,joomla,foreach,Php,Joomla,Foreach,我目前正在尝试覆盖joomla菜单,使其看起来像: 项目|项目|项目|项目标志项目|项目|项目|项目 因此,基本上我正试图将菜单一分为二,但不幸的是,我神奇地把它弄坏了 以下是菜单的未编辑代码: <?php /** * @package Joomla.Site * @subpackage mod_menu * * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights rese

我目前正在尝试覆盖joomla菜单,使其看起来像:

项目|项目|项目|项目标志项目|项目|项目|项目

因此,基本上我正试图将菜单一分为二,但不幸的是,我神奇地把它弄坏了

以下是菜单的未编辑代码:

<?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>

>

这是我编辑的代码,直到现在它还在工作:

<?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>

>

您最好使用Joomla选项来实现这一点,这样就不需要测试$counter了。在“菜单管理器”中,编辑菜单项,然后在“链接类型选项”中选择并添加链接图像。然后在每个循环的代码中:

   $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>';
        }
$spanImg='';
如果($item->menu\u image){
$spanImg='菜单图像'“/>”;
}
...
//下一个项目更深入。
如果($item->deep)
{
echo'
    ; } ... //下一项在同一级别。 否则{ echo$spanImg.“”; }

否则,当您调用default_url.php时,您可以在此文件中找到这段代码,它也应该可以工作。

使用
$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>

>

嘿,谢谢,伙计,但问题是我对我提出的解决方案做了太多CSS,如果我不得不改变这种方法,我会损失太多…不过下次我会记住的