我正在尝试在页面中的 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]);
关于php - 外部页面中的 Joomla 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12018778/