Add a Special Banner and a Typical Banner
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.