为Joomla 2.5和3.x使用下面的代码用单一语言站点:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is homepage';
}
?>
对于多语言网站,检测网页(头版)取决于当前所选的语言,所以你需要使用类似以下内容:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault('en-GB')) {
echo 'This is English homepage';
}
elseif ($menu->getActive() == $menu->getDefault('it-IT')) {
echo 'This is Italian homepage';
}
?>
对于多语言网站,您还可以使用下面的代码:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
if ($menu->getActive() == $menu->getDefault($lang->getTag())) {
echo 'This is homepage';
}
else {
echo 'This is not homepage';
}
?>
希望它能帮助!
谢谢!这正是我所期待的。 – Mala 2009-11-18 20:35:24
如果安装具有名为“frontpage”的视图的其他组件,则可能会中断。为了确保你在查看内容组件,我会这样写'if'语句:if(JRequest :: getVar('view')=='frontpage'&& JRequest :: getVar('option')= ='com_content') – jlleblanc 2009-11-18 21:52:38
如果您在首页使用com_content正面页面视图,而不是其他组件,则它可以正常工作。 – 2009-11-19 07:31:36