外部页面中的Joomla菜单


Joomla Menu In External Page

我正试图在Joomla的模板文件夹之外的页面中从Joomla中的主菜单重新创建菜单项。

有没有任何可用的方法,比如Wordpress中的"wp_nav_menu",可以帮助我生成菜单。

您需要遵循的两个步骤

首先,使您的外部页面能够运行joomla库。要做到这一点,您需要在外部php页面中包含几行代码

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__).'/../../../../' );   // should point to joomla root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

其次,为您想要的菜单创建一个菜单模块,并在自定义位置启用它,比如"xxxx"然后把下面的代码放在你想放菜单的地方

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModules('xxxx');
// xxxx is any virtual position, no need to create it anywhere.
echo JModuleHelper::renderModule($module[0]);