1. Count the modules
$this->countModules()
<?php if($this->countModules('left')) { ?>
<div id="left"><jdoc:include type="modules" name="left" /></div>
<?php } ?>
2. Checking for the frontpage
JRequest::getCmd(‘view’)
JRequest::getCmd(‘view’) == ‘article’) { ?>
3. Checking for another component
JRequest::getCmd(‘option’)
JRequest::getCmd(‘option’) == ‘com_kunena’) { ?>
4. Both component and layout
JRequest::getCmd(‘option’) == ‘com_content’
&& JRequest::getCmd(‘view’) == ‘frontpage’) { ?>
5.Checking for the actual homepage
$menu = JSite::getMenu();
$active = $menu->getActive();
$home = (boolean)$active->home;
6.Checking for a specific module
jimport(‘joomla.application.module.helper’);
$instance = JModuleHelper::getModule(‘mod_login’);
$login_module = (is_object($instance)) ? true : false;
7 . front page detection:
& JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo JHTML::script(‘mobile.js’,’ ‘);
} ?>
8. front page detection details
Front page Checking?
Basic code
<?php $menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
} ?>
For multi-language sites use this code
Show different content based on selected language
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault( 'en-GB' )) {
echo 'This is the front page';
}
elseif ($menu->getActive() == $menu->getDefault( 'fr-FR' )) {
echo 'Il s'agit de la premi?re page';
}
?>
Call to a member function getActive()
You forgot to define $menu, add
$menu = & JSite::getMenu();
For Joomla 1.5 :use these code.
JRequest::getCmd(‘view’) == ‘frontpage’) { // do something} ?>
Some templates may have defined function inside ja_templatetools.php, for example JA-purity has
<?php function isFrontPage(){ return (JRequest::getCmd( 'view' ) == 'frontpage') ; } ?>
so in this case can know, whether it’s Frontpage, by using code:
|
|
In Joomla 1.7, joomla 2.5, joomla 2.5.7 version, you can use the same code, except there is no view ‘frontpage’.
You can see, what view does Frontpage has, by inserting
|
|
after body tag in template’s index.php file. Refresh browser and somewhere in top of website you will see name of view.
If frontpage is article or last articles from some category, you better get
|
|
to work. Because in this case getCmd(‘view’) will return same view also in articles/category (not frontpage).
This option really should be used as last resort, because it won’t allow much flexibility.
Examples
Add
|
|
to beginning of template’s index.php file
Every time, you want to check if user is on frontpage, use
|
|
Show text on
|
|
Show module
|
|
Hide module
|
|
only difference from previous example is little exclamation mark in if statement
Show long HTML code
|
|
Add CSS class
|
|
Then of course define body.classname {} in your CSS file
Include Javascript
Paste this between head tags
|
|
As you see, after recognizing Frontpage, usage is unlimited. You can literally turn homepage’s design upside down, including or excluding specific content and applying CSS styles. Paraphrasing post’s title, If Joomla Front page (homepage), do anything.
