home page check
- igd
- Joomla! Apprentice
- Posts: 33
- Joined: Thu May 11, 2006 6:51 am
- Location: Ellensburg, Washington
- Contact:
home page check
in my template index.php what basic php if/else can i do to check and see if I am on the home page.
Dan Syme - InnerGate Designs
- ooffick
- Joomla! Master
- Posts: 11615
- Joined: Thu Jul 17, 2008 3:10 pm
- Location: Ireland
- Contact:
Re: home page check
Hi,
the simplest one would be to do the following:
Olaf
the simplest one would be to do the following:
Code: Select all
<?php if(JRequest::getVar('view') == "frontpage" ) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>
Olaf Offick - Global Moderator
learnskills.org
learnskills.org
- igd
- Joomla! Apprentice
- Posts: 33
- Joined: Thu May 11, 2006 6:51 am
- Location: Ellensburg, Washington
- Contact:
- andpatton
- Joomla! Apprentice
- Posts: 23
- Joined: Fri May 29, 2009 3:50 pm
- Contact:
Re: home page check
I recently wanted to do a home page check in a template for a site that didn't use the 'frontpage' view, which made Olaf's method inapplicable.
There's a fairly easy way to do a more robust check, however, one that checks what the default menu item is and if it's the current menu item, rather than just checking if it's the frontpage view:
There's a fairly easy way to do a more robust check, however, one that checks what the default menu item is and if it's the current menu item, rather than just checking if it's the frontpage view:
Code: Select all
<?php $menu = &JSite::getMenu();
if (JRequest::getInt('Itemid') == $menu->getDefault()) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>
-
- Joomla! Fledgling
- Posts: 1
- Joined: Sun Jan 09, 2011 5:41 pm
Re: home page check
I have been searching the forums and have yet to find an answer to my particular issue. I need to have a php if and else statement that will output certain javascript if joomla is on a certain page only. The page is not the home page, so I can't use that code. I have looked for ways to filter to whatever page you want, but to no avail.
If page is 2nd menu link, then print these javascripts in head, else do not print javascipts.
If page is 2nd menu link, then print these javascripts in head, else do not print javascipts.
- andpatton
- Joomla! Apprentice
- Posts: 23
- Joined: Fri May 29, 2009 3:50 pm
- Contact:
Re: home page check
You only want this JS on a single page? If so, just find out that menu item's ID (go to Menus -> [Your Menu], and find the number in the "ItemID" column for the page's menu item). Then, put the following code in the <head> of your template, where you replace your_id with the number you just found:safani wrote:If page is 2nd menu link, then print these javascripts in head, else do not print javascipts.
Code: Select all
<?php if (JRequest::getInt('Itemid') == your_id) : ?>
<!-- special javascript -->
<?php endif; ?>
-
- Joomla! Apprentice
- Posts: 47
- Joined: Fri Sep 07, 2007 3:54 am
Re: home page check
Code: Select all
<?php if (JRequest::getInt('Itemid') == your_id) : ?>
<!-- special javascript -->
<?php endif; ?>
Does anyone know another solution for Joomla 1.6?
- andpatton
- Joomla! Apprentice
- Posts: 23
- Joined: Fri May 29, 2009 3:50 pm
- Contact:
Re: home page check
You just need to adapt one line of the existing code, I believe. I don’t have an install where I quickly test this, butosnysantos wrote:Does anyone know another solution for Joomla 1.6?
Code: Select all
<?php $menu = JFactory::getApplication()->getMenu();
if (JRequest::getInt('Itemid') == $menu->getDefault()) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>
-
- Joomla! Apprentice
- Posts: 47
- Joined: Fri Sep 07, 2007 3:54 am
Re: home page check
doesn't work...
-
- Joomla! Apprentice
- Posts: 37
- Joined: Thu Feb 03, 2011 6:02 am
Re: home page check
@andpatton:
I am using joomla 1.6 and I have used your suggested code but its else portion is working just. It is not getting the "if" portion. Can anybody guide me please?
Regards and thanks
I am using joomla 1.6 and I have used your suggested code but its else portion is working just. It is not getting the "if" portion. Can anybody guide me please?
Regards and thanks
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Dec 27, 2010 2:36 pm
Re: home page check
what if i want to check for pages other than the homepage?
-
- Joomla! Apprentice
- Posts: 37
- Joined: Thu Feb 03, 2011 6:02 am
-
- Joomla! Fledgling
- Posts: 1
- Joined: Fri Sep 23, 2011 5:53 pm
Re: home page check
I am working in Joomla 1.7 and this worked perfectly for me.kurian_86 wrote:follow this link:http://docs.joomla.org/How_to_determine ... front_page
http://servatordesign.com => Web site development
-
- Joomla! Fledgling
- Posts: 2
- Joined: Sun Feb 12, 2012 11:23 pm
Re: home page check
Yes, 1.7 solution works in 2.5, also.
from here:
http://docs.joomla.org/How_to_determine ... front_page
Code: Select all
<?php
$menu = JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}
?>
http://docs.joomla.org/How_to_determine ... front_page
-
- Joomla! Explorer
- Posts: 455
- Joined: Fri Nov 11, 2011 9:43 pm
- Location: Chicago, IL
Re: home page check
Being Joomla is OOP you can chain the methods preventing any need to declare classes.
If someone needs multi-language or varying default pages depending on language you should certainly review the Joomla Documentation link from mdb172.
Code: Select all
<?php if (JFactory::getApplication()->getMenu()->getActive() == JFactory::getApplication()->getMenu()->getDefault()) : ?>
echo "I'm a front page!";
<?php else : ?>
echo "I bring dishonor to this page...";
<?php endif; ?>
-
- Joomla! Explorer
- Posts: 455
- Joined: Fri Nov 11, 2011 9:43 pm
- Location: Chicago, IL
Re: home page check
You should just assume that what works in 1.5 won't work in 2.5. Since 1.6 and 1.7 were transitions, a lot of legacy functionality was depreciated, meaning some legacy extensions still worked. That is not the case with 2.5 which officially removed all depreciated classes and methods.
The below code does the same for 1.5:
The below code does the same for 1.5:
Code: Select all
if (JSite::getMenu()->getActive() == JSite::getMenu()->getDefault()) {
echo 'This is the front page';
}
-
- Joomla! Apprentice
- Posts: 19
- Joined: Thu Jun 28, 2012 2:34 am
Re: home page check
Hi pals,
in Joomla 2.5.6
will work, pls check that in other versions too
Thanks
Anes
in Joomla 2.5.6
Code: Select all
<?php if(JRequest::getVar('view') == "featured" ) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>
Thanks
Anes
-
- Joomla! Fledgling
- Posts: 1
- Joined: Fri Jan 18, 2013 9:48 am
Re: home page check
This works for joomla but it doesnt work in Jomres inner pages. I am using jomres on home page and when I click on a property to view property details it still renders it on the home page so
doesnt work on those inner pages as it will still be consideres home page. you have to implement custom checks by getting current URL etc.
Code: Select all
if($this->countModules( 'position_name' )
Code: Select all
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault() && !$matched) {
Last edited by ooffick on Sun Jan 20, 2013 10:40 am, edited 1 time in total.
Reason: Mod Note: Removed manual Signature. Please read the Forum rules for details.
Reason: Mod Note: Removed manual Signature. Please read the Forum rules for details.
- garkell
- Joomla! Apprentice
- Posts: 42
- Joined: Mon Aug 31, 2009 9:32 pm
- Location: Australia
- Contact:
Re: home page check
In Joomla! 3.0.3 I did the following which works on basic test, but if anyone can point out any issues with using this mechanism I would appreciate it.
Code: Select all
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive()->home) {
echo 'This is Home Page';
}
-
- Joomla! Apprentice
- Posts: 12
- Joined: Mon Oct 30, 2006 8:14 am
- Location: Russia
- Contact:
Re: home page check
Code: Select all
if(JURI::root()!=JURI::current()) {
//not mainpage
}else{
//mainpage
}