0

I have used clever template and edited index.php file by adding some lines of code:

<div class="col span_8">
          <div id="message">
           <h2>
             Message From The President<hr>

            </h2> 
             <img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/president.jpg" width="100" height="100" alt="president">
             <p>

            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </p>
          </div>
        </div>

But, this is appearing on every single page? How do i make it appear only on homepage?

2

Rather than editing the index.php file, I recommend:

  • creating a custom HTML module in Extensions -> Modules
  • publishing the module to a suitable module position and setting the module to display only on the Home Page via the options under the Menu Assignment tab
1

Neil's answer about assigning a module would be the best way to work with Joomla - the template should really just contain the shared elements.

If you still need to detect the homepage as part of your template, however, then you would use the following code:

<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) { ?>
    <div class="col span_8">
          <div id="message">
           <h2>
             Message From The President<hr>

            </h2> 
             <img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/president.jpg" width="100" height="100" alt="president">
             <p>

            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </p>
          </div>
        </div>
<?php } ?>

This works by checking if the current menu item object is the same as the default menu item's object. If it is, that means you are on the default page.

If you have a multilingual site, this is slightly different. See Joomla's documentation for further details.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.