Joomla模板

在模板里判断是否是首页How to determine if the user is viewing the front page,别名

日期:2017-05-20 阅读:2162

dmandwp系统 - wordpress系统和DM系统区块建站>>


进入网易云课堂播放
    |    更多视频教程>

https://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page

在模板的index.php写下面代码测试:
$app = JFactory::getApplication(); //这个在index.php里有的。


$menu = $app->getMenu();
//var_dump($menu);
if ($menu->getActive() == $menu->getDefault()) {
     echo 'This is the front page';
}

如果是多语言,则要用下面判断
$lang = JFactory::getLanguage();
if ($menu->getActive() == $menu->getDefault($lang->getTag())) {
    echo 'This is the front page';
}

而$lang->getTag()则是zh-CN
其实在模板里也有这个代码:

<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">

echo $this->language;结果是zh-cn(小写了)

------------------

得到别名:

echo $menu->getActive()->alias;

<body class="<?php echo $active->alias; ?> ">这样,就可以自定义class了

 

 

 

<<点击返回