The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Mon Jun 30, 2008 8:06 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Nov 15, 2007 8:29 pm
Posts: 35
Hello Everyone!

I used the following code in a Joomla 1.0 template to check to see if the current page is the homepage (fronpage):
Code:
<?php
if ($option == 'com_frontpage' )
{
// This is the front page
}
else
{
//this is not the front page
}
?>


Can someone please tell me how I would do this in 1.5? IS there a way to grab the 'view' variable in the url to see if it is 'front page'?


Top
 Profile  
 
PostPosted: Thu Jul 03, 2008 5:33 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Nov 15, 2007 8:29 pm
Posts: 35
For all of you reading this post, I figured it out. You can use the following code to detect frontpage.
Code:
<?php if (JRequest::getVar('view') == 'frontpage')
{
echo 'this is front page';
}
?>


Top
 Profile  
 
PostPosted: Thu Jul 17, 2008 7:41 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Jul 07, 2008 8:31 pm
Posts: 6
This also works:

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

_________________
Please read forum rules regarding signatures: viewtopic.php?t=65


Top
 Profile  
 
PostPosted: Wed Aug 06, 2008 12:27 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Aug 06, 2008 12:21 pm
Posts: 2
Thanks for the tip, but when I put this on my template I get
Quote:
PHP Fatal error: Class 'JSite' not found
. Why is this? Is it not allowed to use this on templates or should I be including the JSite somehow? :eek:


Top
 Profile  
 
PostPosted: Wed Aug 06, 2008 7:39 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Jul 07, 2008 8:31 pm
Posts: 6
Try putting this somewhere before the frontpage checking:

Code:
    <?php
   $pageoption = JRequest::getVar( 'option', '' );
   ?>

_________________
Please read forum rules regarding signatures: viewtopic.php?t=65


Top
 Profile  
 
PostPosted: Wed Aug 06, 2008 7:52 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Aug 06, 2008 12:21 pm
Posts: 2
Well actually that wouldn't work either. I figured out what's wrong. Quite embarrassingly I had not checked the version of my Joomla :-[ I'm using the 1.0 stable version. I guess I just assumed most people would be using the stable one. So the solution for 1.0 is found earlier on this thread :P


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 4:38 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Aug 19, 2008 4:56 pm
Posts: 2
mapangpang wrote:
This also works:

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


there is an error in this code it should read:

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


At least in PHP 5, the triple equals is necessary because it says that the items are exactly the same, otherwise it won't be considered equal


Top
 Profile  
 
PostPosted: Tue Sep 15, 2009 9:16 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Sep 15, 2009 9:08 pm
Posts: 1
byoung618 wrote:
For all of you reading this post, I figured it out. You can use the following code to detect frontpage.
Code:
<?php if (JRequest::getVar('view') == 'frontpage')
{
echo 'this is front page';
}
?>


byoung618, Thanks for your code! It worked!
I have also tried that other code, but it may show your content on other pages besides the defalt one since it relies on ItemID thing which may be inherited from the previous page you've visited :(
Code:
<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
   echo 'This is the front page';
}
?>


Top
 Profile  
 
PostPosted: Mon Aug 08, 2011 2:25 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Dec 12, 2006 8:37 pm
Posts: 119
In my case, content is linked to the main page menu. So, besides the front page, all content pages were considered as "frontpage" due to the linking to that default menu item.

As by now my solution for Joomla 1.7 (will work in 1.6 too) is
Code:
function isFrontPage() {
   
    $mainframe = JFactory::getApplication();   
    $sef = $mainframe->getCfg( 'sef' );
    $menu = JSite::getMenu();
   
    if ( $sef ) {
        $uri = JURI::getInstance()->toString( array( 'path' ) );
        if ( $menu->getActive() === $menu->getDefault() && ( $uri == '/index.php' || $uri == '/' ) ) {
            return true;
        }
    } else {
        $uri = JURI::getInstance()->toString( array( 'query' ) );
        if ( $menu->getActive() === $menu->getDefault() && ( $uri == '' || substr( $uri, 0, 12 ) == '?limitstart=' ) ) {
            return true;
        }
    }
    return false;
}

_________________
www.justPHP.net - HACKS for Hot Property, Custom 404 Error Pages, Templates for Joomla etc.
Developing: www.zerno.org.ua


Top
 Profile  
 
PostPosted: Sun Sep 18, 2011 8:53 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Sep 18, 2011 8:38 am
Posts: 8
Location: India
Wow thats great sir
Its working for me nice
THX

_________________

KaviarasanKK


Top
 Profile  
 
PostPosted: Wed Jan 18, 2012 5:25 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Sep 18, 2011 8:38 am
Posts: 8
Location: India
You can try this for Joomla 1.6 & 1.7 - 1.7.3 (It works good for me)


$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');

$frontpage = ($option == 'com_content' && $view == 'featured');
$article = ($option == 'com_content' && $view == 'article');

if ($frontpage){
//Your front Page
}
else{
//Your Article Page
}

/**************************************/
if($article){
// Your Article Page
}

_________________

KaviarasanKK


Top
 Profile  
 
PostPosted: Mon Jan 30, 2012 6:36 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jan 28, 2012 8:55 am
Posts: 7
byoung618 wrote:
Hello Everyone!

I used the following code in a Joomla 1.0 template to check to see if the current page is the homepage (fronpage):
Code:
<?php
if ($option == 'com_frontpage' )
{
// This is the front page
}
else
{
//this is not the front page
}
?>


Can someone please tell me how I would do this in 1.5? IS there a way to grab the 'view' variable in the url to see if it is 'front page'?


In later versions of joomla 1.5 com_frontpage is not available. The code mentioned above do work . For versions 1.6 and later there is more info here.
http://docs.joomla.org/How_to_determine ... front_page

Hope that helps

_________________
http://mxbpointcodes.com


Last edited by raghavmitra on Tue Jan 31, 2012 6:17 am, edited 3 times in total.

Top
 Profile  
 
PostPosted: Tue Jan 31, 2012 3:31 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Sep 18, 2011 8:38 am
Posts: 8
Location: India
for 1.5 Instead of "featured" use "frontpage" as like below

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');

$frontpage = ($option == 'com_content' && $view == 'frontpage');
$article = ($option == 'com_content' && $view == 'article');

if ($frontpage){
//Your front Page
}
else{
//Your Article Page
}


I think it may works?

_________________

KaviarasanKK


Top
 Profile  
 
PostPosted: Sun Feb 19, 2012 2:24 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Feb 19, 2012 2:21 pm
Posts: 1
kaviarasankk wrote:
for 1.5 Instead of "featured" use "frontpage" as like below

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');

$frontpage = ($option == 'com_content' && $view == 'frontpage');
$article = ($option == 'com_content' && $view == 'article');

if ($frontpage){
//Your front Page
}
else{
//Your Article Page
}

free Microsoft points Codes

I think it may works?


Yeah kaviarasankk, I can confirm that works for me as well!
Gunna set about implementing it later :)


Top
 Profile  
 
PostPosted: Mon Mar 12, 2012 9:40 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Mar 12, 2012 9:24 am
Posts: 1
Thanks a lot, I was stuck on that issue for quite some time this morning and now I got it working.


Top
 Profile  
 
PostPosted: Tue Jan 29, 2013 10:08 am 
Joomla! Intern
Joomla! Intern

Joined: Thu Dec 15, 2011 8:02 pm
Posts: 67
Location: Israel
Hi everyone,

What if I want to show/hide modules by url parameter?
The best idea as I understand is to show/hise the divs, but how do I do it? (I'm not that good in PHP, sorry)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 



Who is online

Users browsing this forum: No registered users and 9 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