dongyang4615 2016-10-30 02:07
浏览 78
已采纳

Joomla模板php检查是否查看登录注册页面

So in my templates/templatename/index.php I did the following code to check if the user is viewing the registration, login, reminder or forgot password pages as to NOT display / insert adverts on those particular pages.

But for some reason my code is not working and I can't figure out why.

<?php if(JFactory::getUser()->guest) : ?>
<?php if(JRequest::getVar('view') !== 'login' || JRequest::getVar('view') !== 'reset' || JRequest::getVar('view') !== 'remind' || JRequest::getVar('view') !== 'registration') : ?>
<?php include(JPATH_BASE . '/' . 'advert.php'); ?>
<?php endif; ?>
<?php endif; ?>

Pages / urls the advert.php includes should not be present on.

index.php?option=com_users&view=login

index.php?option=com_users&view=reset

index.php?option=com_users&view=remind

index.php?option=com_users&view=registration

Thanks to anyone who can point out what I am doing wrong.

//EDIT : SEF Url's too

/login.html

/reset.html

/remind.html

/registration.html

  • 写回答

1条回答 默认 最新

  • dqvy87517 2016-10-31 09:58
    关注

    Instead of || [OR] use && [AND]

    if(JRequest::getVar('view') !== 'login' && JRequest::getVar('view') !== 'reset' && JRequest::getVar('view') !== 'remind' && JRequest::getVar('view') !== 'registration')
    

    here is some explanation from PHP manual

    $a or $b TRUE if either $a or $b is TRUE.
    $a and $b TRUE if both $a and $b are TRUE.

    Other way you can try is using $option instead of $view

    $option != 'com_user'
    

    in joomla 3.x you can take this parameter by

    $option   = $app->input->getCmd('option', '');
    

    take a look at protostar default template

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来