Posted On July 25, 2020

Ok So we want to show some custom content at home page of opencart site.

May be you want to display some banner image at sidebar or some javascript to header section or any other custom text anywhere on the template but only visible on homepage.

Here is the solution:

Opencart treat home page in two ways. First your base url (naked domain) is the home page and another is home route url that is http://Yourowndomain.com/index.php?route=common/home

So the second part help is available at this link http://opencart.web2y.net/29468-show-a-banner-only-on-home-page-using-php. I am explaining the same here too.

    <?php if (isset($this->request->get[‘route’]) && $this->request->get[‘route’] == ‘common/home’) { ?>

    <!– home page only code/images –>

    <?php } ?>

So this code will solve your issue half but this will not work for the naked domain so if you see at http://yourdomain.com , you find that your custom code is not displaying there.

For that purpose you can use this code

<?php global $base ?>
<?php if($this->url->link == $base) ?>

Here $base is the global variable to use for the base url of opencart site. and to trive its path we use the this->url->link pattern

So combining both of the code you get a full way to show something on only home page in any way.

    <?php global $base ?>

    <?php if (isset($this->request->get[‘route’]) && $this->request->get[‘route’] == ‘common/home’) || if($this->url->link == $base){ ?>

    <!– home page only code/images –>

    <?php } ?>

Happy Coding!