home page check

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
User avatar
igd
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Thu May 11, 2006 6:51 am
Location: Ellensburg, Washington
Contact:

home page check

Postby igd » Wed Feb 25, 2009 2:27 pm

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

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11057
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: home page check

Postby ooffick » Wed Feb 25, 2009 3:11 pm

Hi,

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
Olaf Offick - Global Moderator
http://learnskills.org

User avatar
igd
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Thu May 11, 2006 6:51 am
Location: Ellensburg, Washington
Contact:

Re: home page check

Postby igd » Wed Feb 25, 2009 9:22 pm

cheers your awesome.
Dan Syme - InnerGate Designs

User avatar
andpatton
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri May 29, 2009 3:50 pm
Contact:

Re: home page check

Postby andpatton » Wed Jun 16, 2010 10:43 pm

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: Select all

<?php $menu = &JSite::getMenu();
if (JRequest::getInt('Itemid') == $menu->getDefault()) : ?>
<!-- your home page code -->
<?php else : ?>
<!-- your code -->
<?php endif; ?>

safani
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sun Jan 09, 2011 5:41 pm

Re: home page check

Postby safani » Sun Jan 09, 2011 6:26 pm

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.

User avatar
andpatton
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri May 29, 2009 3:50 pm
Contact:

Re: home page check

Postby andpatton » Mon Jan 10, 2011 3:34 pm

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: Select all

<?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.

osnysantos
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Sep 07, 2007 3:54 am

Re: home page check

Postby osnysantos » Fri Jan 28, 2011 1:17 pm

Code: Select all

<?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?

User avatar
andpatton
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Fri May 29, 2009 3:50 pm
Contact:

Re: home page check

Postby andpatton » Fri Jan 28, 2011 4:14 pm

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: Select all

<?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.

osnysantos
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Sep 07, 2007 3:54 am

Re: home page check

Postby osnysantos » Mon Jan 31, 2011 12:47 am

doesn't work...

kurian_86
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Thu Feb 03, 2011 6:02 am

Re: home page check

Postby kurian_86 » Thu Mar 24, 2011 8:50 am

@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

teensicle
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Dec 27, 2010 2:36 pm

Re: home page check

Postby teensicle » Wed Apr 20, 2011 4:43 pm

what if i want to check for pages other than the homepage?

kurian_86
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Thu Feb 03, 2011 6:02 am

Re: home page check

Postby kurian_86 » Thu Apr 21, 2011 7:05 am

follow this link:http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page

ServatorD
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Sep 23, 2011 5:53 pm

Re: home page check

Postby ServatorD » Fri Sep 23, 2011 7:03 pm

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

mdb172
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Feb 12, 2012 11:23 pm

Re: home page check

Postby mdb172 » Mon Feb 13, 2012 1:47 am

Yes, 1.7 solution works in 2.5, also.

Code: Select all

<?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

bbolli
Joomla! Explorer
Joomla! Explorer
Posts: 455
Joined: Fri Nov 11, 2011 9:43 pm
Location: Chicago, IL

Re: home page check

Postby bbolli » Thu May 31, 2012 11:18 pm

Being Joomla is OOP you can chain the methods preventing any need to declare classes.

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


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

bbolli
Joomla! Explorer
Joomla! Explorer
Posts: 455
Joined: Fri Nov 11, 2011 9:43 pm
Location: Chicago, IL

Re: home page check

Postby bbolli » Fri Jun 01, 2012 3:46 pm

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: Select all

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

admod
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Thu Jun 28, 2012 2:34 am

Re: home page check

Postby admod » Fri Jul 06, 2012 12:44 pm

Hi pals,
in Joomla 2.5.6

Code: Select all

<?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

natalierey
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Jan 18, 2013 9:48 am

Re: home page check

Postby natalierey » Sat Jan 19, 2013 4:26 am

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: Select all

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: 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.

User avatar
garkell
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Mon Aug 31, 2009 9:32 pm
Location: Australia
Contact:

Re: home page check

Postby garkell » Thu Apr 18, 2013 1:29 am

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';
}

nikonor
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Mon Oct 30, 2006 8:14 am
Location: Russia
Contact:

Re: home page check

Postby nikonor » Fri Jun 07, 2013 6:39 pm

Code: Select all

if(JURI::root()!=JURI::current()) {
//not mainpage
}else{
//mainpage
}


Return to “Joomla! 1.5 Coding”

Who is online

Users browsing this forum: No registered users and 11 guests