C0nw0nk C0nw0nk - 1 month ago 9
PHP Question

Joomla template php checking if viewing login registration pages

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

Answer

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