The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ] 
Author Message
 Post subject: home page check
PostPosted: Wed Feb 25, 2009 2:27 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu May 11, 2006 6:51 am
Posts: 33
Location: Ellensburg, Washington
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


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Wed Feb 25, 2009 3:11 pm 
User avatar
Joomla! Master
Joomla! Master

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 10926
Location: Ireland
Hi,

the simplest one would be to do the following:

Code:
<?php if(JRequest::getVar('view') == "frontpage" ) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>


Olaf

_________________
Olaf Offick - Global Moderator
http://learnskills.org


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Wed Feb 25, 2009 9:22 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu May 11, 2006 6:51 am
Posts: 33
Location: Ellensburg, Washington
cheers your awesome.

_________________
Dan Syme - InnerGate Designs


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Wed Jun 16, 2010 10:43 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri May 29, 2009 3:50 pm
Posts: 23
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:
Code:
<?php $menu = &JSite::getMenu();
if (JRequest::getInt('Itemid') == $menu->getDefault()) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>

_________________
http://www.acusti.ca


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Sun Jan 09, 2011 6:26 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Jan 09, 2011 5:41 pm
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Mon Jan 10, 2011 3:34 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri May 29, 2009 3:50 pm
Posts: 23
safani wrote:
If page is 2nd menu link, then print these javascripts in head, else do not print javascipts.

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:
Code:
<?php if (JRequest::getInt('Itemid') == your_id) : ?>
<!-- special javascript -->
<?php endif; ?>

The "special javascript" will only be printed if your are currently viewing the page specified.

_________________
http://www.acusti.ca


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Jan 28, 2011 1:17 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Sep 07, 2007 3:54 am
Posts: 47
Code:
<?php if (JRequest::getInt('Itemid') == your_id) : ?>
<!-- special javascript -->
<?php endif; ?>


This is the only solution that works in Joomla 1.6 apparently...
Does anyone know another solution for Joomla 1.6?


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Jan 28, 2011 4:14 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri May 29, 2009 3:50 pm
Posts: 23
osnysantos wrote:
Does anyone know another solution for Joomla 1.6?

You just need to adapt one line of the existing code, I believe. I don’t have an install where I quickly test this, but
Code:
<?php $menu = JFactory::getApplication()->getMenu();
if (JRequest::getInt('Itemid') == $menu->getDefault()) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>

should work. The method of getting the $menu is the only thing that has changed, as far as I can tell.

_________________
http://www.acusti.ca


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Mon Jan 31, 2011 12:47 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Sep 07, 2007 3:54 am
Posts: 47
doesn't work...


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Thu Mar 24, 2011 8:50 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 03, 2011 6:02 am
Posts: 37
@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


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Wed Apr 20, 2011 4:43 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Dec 27, 2010 2:36 pm
Posts: 5
what if i want to check for pages other than the homepage?


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Thu Apr 21, 2011 7:05 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 03, 2011 6:02 am
Posts: 37
follow this link:http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Sep 23, 2011 7:03 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Sep 23, 2011 5:53 pm
Posts: 1
kurian_86 wrote:
follow this link:http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page


I am working in Joomla 1.7 and this worked perfectly for me.

_________________
http://servatordesign.com => Web site development


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Mon Feb 13, 2012 1:47 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Feb 12, 2012 11:23 pm
Posts: 2
Yes, 1.7 solution works in 2.5, also.

Code:
<?php
$menu = JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
   echo 'This is the front page';
}
?>


from here:
http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Thu May 31, 2012 11:18 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Fri Nov 11, 2011 9:43 pm
Posts: 451
Location: Chicago, IL
Being Joomla is OOP you can chain the methods preventing any need to declare classes.

Code:
<?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; ?>


If someone needs multi-language or varying default pages depending on language you should certainly review the Joomla Documentation link from mdb172.


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Jun 01, 2012 3:46 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Fri Nov 11, 2011 9:43 pm
Posts: 451
Location: Chicago, IL
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:

Code:
if (JSite::getMenu()->getActive() == JSite::getMenu()->getDefault()) {
   echo 'This is the front page';
}


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Jul 06, 2012 12:44 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Jun 28, 2012 2:34 am
Posts: 19
Hi pals,
in Joomla 2.5.6

Code:
<?php if(JRequest::getVar('view') == "featured" ) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>


will work, pls check that in other versions too

Thanks
Anes


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Sat Jan 19, 2013 4:26 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Jan 18, 2013 9:48 am
Posts: 1
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
Code:
if($this->countModules( 'position_name' )

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:
$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.
Mod Note: Removed manual Signature. Please read the Forum rules for details.


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Thu Apr 18, 2013 1:29 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Aug 31, 2009 9:32 pm
Posts: 20
Location: Australia
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:
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive()->home) {
    echo 'This is Home Page';
}


Top
 Profile  
 
 Post subject: Re: home page check
PostPosted: Fri Jun 07, 2013 6:39 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Oct 30, 2006 8:14 am
Posts: 12
Location: Russia
Code:
if(JURI::root()!=JURI::current()) {
//not mainpage
}else{
//mainpage
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ] 



Who is online

Users browsing this forum: Exabot [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group