爲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