How do I show banner only on homepage

Started by timeindicator, September 16, 2014, 08:53:13 PM

Previous topic - Next topic

timeindicator

Hi,

I have hardcoded a banner on index.template.php.  However, it shows up on all pages as well.  How do I make it show only on index page.

mashby

Welcome to SMF! :)

Try Themes/default/BoardIndex.template.php

Or BoardIndex.template.php if you are using a custom theme and such a file exists. If it doesn't, the default file is the place to go.
Always be a little kinder than necessary.
- James M. Barrie

timeindicator

Hi,

Thanks for the quick reply.  Just one more thing, this is like a hardcoded sidebar that has been added on the index.template.php and I just need the image to be shown on the homepage itself.  Can this be done just using a if statement on the index.template.php or I still have to move it to boardindex.template. php?

mashby

index.template.php affects all pages on the site. Think of it as the theme wrapper. And BoardIndex.template.php is the main forum index page but uses index.template.php for its wrapper. Want something on every page? index.template.php. Just the home page, BoardIndex.template.php.
Always be a little kinder than necessary.
- James M. Barrie

Hj Ahmad Rasyid Hj Ismail

There is other way too but you have to define the Index page since SMF didn't do so, otherwise there is no way the hardcoded banner code knows it suppose to show only in Index page.

What you need to do is, add a code in BoardIndex.php e.g.
Find:
loadTemplate('BoardIndex');

// Set a canonical URL for this page.
$context['canonical_url'] = $scripturl;

Replace
loadTemplate('BoardIndex');

// Set a canonical URL for this page.
$context['canonical_url'] = $scripturl;

// Set ID for this page.
$context['hardcoded_banner'] = true;



Then when you add your hardcoded banner code in index.template.php, simply check whether this exist, like this:
if ($context['hardcoded_banner']) {
echo '
insert your hardcoded banner code properly and don't forget to close the echo too
}


That way, similarly, it won't be showing except in the Index page.

Advertisement: