外部页面中的 Joomla 菜单
I am trying to re-create the menu items from main menu in Joomla in a page, which is outside Joomla's template folder.
Are there any method available, such as 'wp_nav_menu' in Wordpress, which would help me to generate the Menu.
解决方案There are two steps that you will need to follow
First, make your external page capable of running joomla library. To do this you will need to include few lines of code in your external php page
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();
Second, Create a menu module for your desired menu and enable it on a custom position say 'xxxx' and then put the following code where you want the put that menu
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]);
相关文章