我目前正在创建一个 joomla 菜单模块,但我遇到了一些问题..
我正在尝试将子菜单项分成 3 列,目前我正在使用这个:
$counter = 0;
if($item->level == 2):
$counter += count($item);
endif;
if($item->level == 1):
$counter = 0;
endif;
if($counter%3 == 0 && $item->level == 2){
echo '</ul><ul class="col-lg-3">';
}
但这只是将它们分组为 3
这是整个 default.php:
<?php
// No direct access
defined('_JEXEC') or die;
// Note. It is important to remove spaces between elements.
$counter = 0;
?>
<ul class="nav navbar-nav <?php echo $class_sfx; ?> nav-mega"<?php
$tag = '';
if ($params->get('tag_id') != null)
{
$tag = $params->get('tag_id') . '';
echo ' id="' . $tag . '"';
}
?>>
<?php
foreach ($list as $i => &$item) {
if($item->level == 2):
$counter += count($item);
endif;
if($item->level == 1):
$counter = 0;
endif;
$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->deeper){
$class .= ' deeper dropdown';
}
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':
require JModuleHelper::getLayoutPath('mod_blogmenu', 'default_' . $item->type);
break;
default:
require JModuleHelper::getLayoutPath('mod_blogmenu', 'default_url');
break;
}
// The next item is deeper.
if($counter%3 == 0 && $item->level == 2){
echo '</ul><ul class="col-lg-3">';
}
if ($item->deeper){
echo '<div class="dropdown-menu mega-dropdown">';
echo '<div class="mega-image col-lg-3 thumbnail visible-md visible-lg"><img src="'.$item->menu_image.'" /></div>';
echo '<ul class="col-lg-3">';
}
// The next item is shallower.
elseif ($item->shallower){
echo str_repeat('</ul><div class="mega-caption"></div></div>', $item->level_diff);
}
// The next item is on the same level.
else {
//echo '</li>';
}
}
?>
</ul>
对不起很多代码;我仍在努力学习 PHP 并尝试了解 Joomla 的做事方式,这对我来说并不容易。