How to hide the maincontent on the home page

Template Creator CK has an option to create a home page without the maincontent part. This allows you to use only modules / widgets on the front page.

Go in Parameters >> Page >> Template / Theme parameters >> Hide frontpage content = YES

This will automatically detect the home page of your website and disable the maincontent section.

 

How to hide the maincontent or other section on specific pages

Sometimes you will need to hide a section of your template / theme depending on the page of the website. I will show you a simple method that works into Template Creator CK and that don't need to edit the template files manually. We will see how to hide the maincontent on the home page, but you can adapt this method to any other situation.

You will be able to use this technique directly in the interface and then adapt the code to what you want to hide the maincontent block (or any other block) on the pages you want.

 

1/ Add the custom code in the HEAD

Edit your template and go in the top menu Parameters >> Custom Code. Copy paste or write the following code and Validate :

<?php
// Detecting Home
$menu = JFactory::getApplication()->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
    $siteHome = 1;
}else{
    $siteHome = 0;
}
?>

This code will be added directly before the closing tag </head>. It will check if you are on the homepage, according the default menu item that you have set in your website. the variable $siteHome will have the value 1 if you are visiting the homepage.

 

2/ Add the custom blocks for the condition

 

In the template edition interface, take a new Custom Block and drag and drop it directly before the Maincontent block. Take another Custom Block and put it just after the Maincontent block. Your maincontent block must now have a custom block just before and just after it.

 

2.1/ in the first custom block, add this code to begin the condition :

<?php if(! $siteHome) { ?>

This will check the value of the $siteHome, here if were are NOT in the homepage, then we can display the maincontent. This means that the maincontent will be hidden on the homepage only.

 

2.2/ in the second custom block, add this code to close the condition :

 <?php } ?>

This will simply mark the end of the condition that we have started before.

 

3/ Preview your template

 

To test this method, you must first Download your template and install it into your website, then assign it by default. You can then test this method, go in the homepage >> the maincontent block will not be shown.

 

Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline