【问题标题】:Accessing contents of a menu in Joomla在 Joomla 中访问菜单的内容
【发布时间】:2015-10-10 01:20:12
【问题描述】:

我无法将 html 文档调整为 Joomla 3.4 CMS 模板。我正在使用引导程序,我想实现导航条代码的以下部分:

<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
    <li><a href="index.php">Home</a></li>
    <li class="active"><a href="services.php">Services</a></li>
    <li><a href="about.php">About</a></li>
    <li><a href="contact.php">Contact</a></li>
</ul>
</div>

我已将所有链接放在同一个菜单中。有没有办法检索菜单中的所有项目,以便我可以在模块中使用它们?

【问题讨论】:

  • 您只有 Joomla 菜单中的那些?您是否为菜单创建了 Joomla 菜单模块?

标签: php html twitter-bootstrap joomla twitter-bootstrap-3


【解决方案1】:

实现这一点的最佳方法是通过“模板覆盖”。

当您创建模块菜单的覆盖时,在文件 default.php 中您可以添加使用 bootstrap 3 所需的结构。

例如,我在覆盖中使用它...

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_menu
 *
 * @copyright   Copyright (C) 2005 - 2014 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 navbar-nav<?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 dropdown-menu">';
	}
	elseif ($item->shallower)
	{
		// The next item is shallower.
		echo '</li>';
		echo str_repeat('</ul></li>', $item->level_diff);
	}
	else
	{
		// The next item is on the same level.
		echo '</li>';
	}
}
?></ul>

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 1970-01-01
    • 2013-01-13
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多