Member Login

You are not currently logged in.






» Register
» Lost your Password?

Video 6 – Adding Different Banners to Different Pages

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

CTLP Lesson 2 – Video 6 – Adding Different Banners to Different Pages from Rick Anderson on Vimeo.

Video 6 – Adding Different Banners to Different Pages

Difficulty Level -

Listed Under Lesson Subjects -

Add a Special Banner and a Typical Banner

Welcome back to the sixth part of this lesson on Customizing Thesis Using PHP. In this part of the lesson we are going to add different header banners to different pages.

Elseif Statement

Let’s switch over here to our IDE. In custom_functions.php we have this function if it’s the home page, then get rid of this action and add this image. What we’re going to now is say if it’s a series of some other pages we are going to remove this action and add a different image. So we are using the elseif inside of this if function. So here’s our opening bracket for if; here’s our closing bracket. What we do now is come down beside that one and type elseif, parenthesis, and then the condition and in this case we’re going to ask if it is one page or another page. And so that is if is_page.

Use Page IDs to Place a Different Banner

If we had only a specific individual page here we were talking about we would just enter the page name or the page ID or something like that. But since we want to include more than one page we have to use what is called an array. And so if is_page, and array, and parenthesis again. Now inside these parenthesis we will put the page IDs that we want to use to add the banner. First we use an opening and close quote and then we’re going to have to go find our page IDs.

So let’s open up our website again and we want the page ID for About and for Demo Page – those are going to have the different banner. Let’s go down here and log into our site so we can pick up these page IDs. Edit pages – if we come over here to our About page and hover over the view you can see down here at the bottom that it says page ID = 2, and then if we look at the Demo page ID = 4. So those are the two page IDs that we’re going to use.

Let’s come over here to the IDE; and the first page was 2 and then we will go beyond the quotes, put a comma, space, opening and closing quotes again and then put 4 and then we’re going to come all the way outside and put our opening and closing curly brackets. So if it’s home then we’re going to remove this action and put this banner in and if it’s the page we’re going to remove this action and put in a different banner.

Special Banner Definition

First, just to help you understand what’s going on here we’ll copy this and then paste it, so remove_action(‘thesis_hook_header’) – same remove action. Escape the PHP to go into html. Go on into html. The link we’re going to keep the same but we want to change the name of this banner image and the image name that we have is CTLP-home-banner.gif. I’m going to change this – I’ve uploaded a special-banner.  And we’re going to hit Save.

What should happen now is if it’s the home page it will remove the action and put the home page banner; else if it’s either page ID 2 or page ID 4 it will remove the header and then add our different banner.

Let’s go ahead and try that. So upload the custom_functions.php file and go to our website. Okay, so there’s our home page banner. Let’s go to About. See there’s our special banner. This is a good place for us to test that. See it still says Go to My Home Page and if we click on this it will take us to the Home Page. And then our typical banner page just has the default Thesis header. So there’s our home page banner, default Thesis header, and our special banner.

Use Else Statement to Add Typical Banner to New Pages

Now we want to add a typical condition so that from now on every time we add a page we get a typical banner. So that is the last thing we’re going to do with this function. Let’s open this back up and just like this elseif was part of the if, this else is also part of the if and so in this case now it’s if it’s home, or else if it’s page 2 or 4, and now we don’t have a conditional tag it’s just going to be else anything. So we’ll put in opening and closing curly brackets. And then we’ll copy this stuff, paste it and then we’re going to change the name of our default header. I believe our default header is just banner so we’re just going to take out special and hyphen there. If it’s home it’s going to get the home banner, if it’s page 2 or 4 it’s going to get the special banner and if it’s any other page it’s going to get the typical banner.

That’s how this thing works. Let’s save this and then we’ll upload it and test it. Okay, this would be the Typical one– there it is. Click on it, it will take us to Home. Here’s our home page banner; this is our different banner. And here we’ll just add one more page. We’re going to Add New – we’ll call it “Another typical Page” and publish it. Go down to Thesis, Options and add it to our Navigation Menu so we can get there. Save it and refresh.

Okay, so there’s “Another Typical Page”, and it’s got the typical header. Demo Page and About are special pages and Home. Now we have put three different banner images and told Thesis which page to put those images on.

The Potential for Consolidating Statements

An experienced PHP coder will see that there’s some repetition in here that doesn’t need to be made, but for the purpose of making this introduction I thought it would be simplest just to clearly spell out each individual condition and write the code for that condition. This code could be consolidated but I just feel like in terms of a beginner understanding what’s going on here it’s probably easier just to let it go like this.

Okay and that wraps up Lesson 2 of the introduction to Customizing Thesis Like a Pro.

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!

{ 26 comments… read them below or add one }

Art Deekens July 21, 2010 at 1:08 pm

Just wondering how you created the blue custom banner you imported into Thesis. I want to learn how to do that, perhaps with Paint.net

Reply

Rick Anderson July 21, 2010 at 2:06 pm

Art, I created those banners in Photoshop. It’s really quite simple and can easily be done in Paint.net. All you do is create a new image, give it a background color and then place text on it. It has very similar functions to any other Windows based application.

If you watch the videos on Paint.net you should be able to get a feel for it.

Reply

Dusibello August 8, 2010 at 1:03 pm

Thanks – one thing I missed: How did you know what to put in ‘more stuff’? I see how you found the proper syntax for the hooks, but I missed how you determined the name of the function you were removing.

Reply

Dennis OBrien October 5, 2010 at 8:17 pm

Having difficulty implementing this code. I can’t find any mistakes can you see anything that may be stopping the header from displaying? The full path to the jpg has been copied form the ftp client. It’s Thesis 1.8 but shouldn’t make a difference. Is there an options setting that may be preventing it form displaying?

remove_action(‘thesis_hook_before_header’, ‘thesis_nav_menu’);
add_action(‘thesis_hook_after_header’, ‘thesis_nav_menu’);
add_action(‘thesis_hook_before_header’, ‘my_custom_banner’);

function my_custom_banner(){

if(is_home()){
remove_action(‘thesis_hook_header’, ‘thesis_default_header’);
?>

<?php
}

}

Reply

Rick Anderson October 6, 2010 at 5:32 am

Dennis – If this is the entire code you are using then you haven’t told it to display anything. All you have done is place an empty link tag in the place of the default header. My guess is that if you look at the page in Firebug you’ll see the empty tag.

In order for a banner to display there you need to reference the image as well – in between the tags.

Reply

chung tang November 23, 2010 at 3:57 pm

Hi Rick,

I don’t use page id’s..instead i use the name of the title ie., about and test page.

I thought it would be as simple as putting ‘about’ instead of ’2′ and ‘test page’ instead of ’4′ but for some reason, my banners won’t show up when I do it that way.

here’s my code that won’t allow the banners to show up…

elseif(is_page(array (‘about’, ‘this is a test page’))){
remove_action (‘thesis_hook_header’, ‘thesis_default_header’);
?>

<?php

Perhaps I need to put something else in place of Array?

Reply

Rick Anderson November 25, 2010 at 6:44 am

Chung Tang – it looks like you might be mixing conventions here. You should be able to use both page name and page slug – however they are case sensitive. Were I writing these titles I’d have written them as “About” and “This is a Test Page”. In my case the page name would need to be written as “About”, etc. If I were using the page slug it would be “about” and “this-is-a-test-page”. I’d make sure you use one or the other but not both. So check the page name and the page slug for the pages.

Reply

steven madar January 4, 2011 at 2:20 pm

Question,

I tried to remove the thesis multimedia box from hook before sidebars and could not do so – maybe the wrong code, also when adding this code:

add_action(‘thesis_hook_after_headline’, ‘thesis_multimedia_box’);

the MM box loads a duplicate at the original sidebar location! How do i remove the duplicate?

You can see it here.
http://www.goldparty.globalgoldandsilver.com

Reply

Rick Anderson January 5, 2011 at 7:52 am

Steven, the problem is that there is no hook for removing the Thesis Multi Media box. And there can only be one instance of the multi media box definition per page. Added to that is that the css for defining its size and location is either fixed, or defined by your Design Options Settings. If you really want to move the multimedia box around you’re better off simulating that rather than actually trying to move it.

Reply

PAUL GIESELMAN January 7, 2011 at 10:10 pm

Hey Rick, do you know of a master list listing key thesis functions such as the ones you use in the demos??? i.e.

thesis_nav_menu
thisis_default_header
thesis_attribution

etcetera, etcetera

great tuts, thanks!

Reply

Rick Anderson January 8, 2011 at 5:45 am

Paul – there are just a few Thesis functions that can be “un-hooked” similar to the ones you’ve listed. The full list of those can be found here in the user manual – http://diythemes.com/thesis/rtfm/default-hook-usage/

Reply

Rick Anderson January 8, 2011 at 9:49 am

Another source for this information, and stuff like that is launch.php inside of theis_18/lib/functions/. This is the file that loads those defaults and it also includes the default filters as well. Until today, I hadn’t even read through this file.

Reply

PAUL GIESELMAN January 8, 2011 at 3:34 pm

Double thanx…cheers

Reply

fchia March 17, 2011 at 12:04 am

Hi Rick,

Good info, three cheers for you.

Thanks.

Felix

Reply

Rick Anderson March 17, 2011 at 6:20 am

You bet – and thanks to your suggestions we’ve begun adding mobile/iPad versions of the videos and download links.

Reply

Aliza Shehpatii April 16, 2011 at 12:38 am

Just bought Thesis for a few days and still looking around for a useful hints on hooks and functions for a newbie cum non-technical guy like me.

Thankfully I’ve managed to discover your site, byobwebsite. A simple yet meaningful guidance for me to start loving my thesis and make it worth every penny I’ve spent!

Reply

Rick Anderson April 16, 2011 at 5:32 am

Aliza, I’m delighted that you found it useful.

Reply

Drew July 1, 2011 at 2:54 am

What if my page has no slug?

when I put this in it shows on all pages except the one I have designated as “home” in the WP reading options.

/* add slider */
function thesis_content_slider() {

}
add_action('thesis_hook_before_content', 'thesis_content_slider');

Reply

Rick Anderson July 1, 2011 at 5:51 am

Drew, in the absence of any conditional it should show up on all page types that have the thesis_hook_before_content hook. Perhaps your home page has a custom template that doesn’t have that hook?

Reply

Chris Godsell February 16, 2012 at 11:19 am

Hi Rick,

The video for this lesson is not embedded.
Do you have a direct link for it that I could follow?
Thanks

Reply

Rick Anderson February 17, 2012 at 8:16 am

Some weird glitch. It’s working now.

Reply

Stefan Pylarinos - Project Life Mastery Blog April 30, 2012 at 6:35 pm

Great content here, recently started using Thesis on my blog and I’m loving it so far. Will make sure I try these out.

Reply

Rick Anderson May 13, 2012 at 9:11 am

I’m glad you’ve found the site to be useful

Reply

beth nagle October 17, 2012 at 1:10 pm

This video is not loading for me. Just a heads up. I did view another video in this series just fine. I am finding that “some” are not working along with this one.

Reply

Rick Anderson October 17, 2012 at 4:55 pm

Yes, we’ve had a problem with some videos. We are trying to resolve it.

Reply

Rick Anderson October 19, 2012 at 5:14 am

This should be resolved now. This will be amazingly easy in Thesis 2.0

Reply

Leave a Comment