Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: timeindicator on September 16, 2014, 08:53:13 PM

Title: How do I show banner only on homepage
Post by: timeindicator on September 16, 2014, 08:53:13 PM
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.
Title: Re: How do I show banner only on homepage
Post by: mashby on September 16, 2014, 09:01:21 PM
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.
Title: Re: How do I show banner only on homepage
Post by: timeindicator on September 16, 2014, 09:14:53 PM
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?
Title: Re: How do I show banner only on homepage
Post by: mashby on September 16, 2014, 10:04:15 PM
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.
Title: Re: How do I show banner only on homepage
Post by: Hj Ahmad Rasyid Hj Ismail on September 17, 2014, 01:50:26 AM
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.