Make Your Thesis Feature Box Content Change Based on Page, Post, Home, Or Whatever!

This post was written for Thesis 1.x. You can find Thesis 2 here.

If you’ve used Thesis, you’ve used the Feature Box. It’s pretty much a Thesis law that you have to put it to use.

Most people just use the Design Options to select where the Feature Box will display.

Not me, though. I’m fancy.

At the time of writing this post, my Feature Box changes based on what part of my website you’re on.

Here’s how I do it.

Dynamic Feature Box for Thesis

The first step is to make sure you have the Feature Box enabled in your Design Options.

Dashboard => Thesis => Design Options

Thesis Feature Box Options

That should do it.

The next thing you’ll want to do is add your own custom PHP to the custom_functions.php file.

Dashboard => Thesis => Custom File Editor => Select “custom_functions.php” from the selection menu and click the button.

1. Stop! 2. Back up your custom_functions.php file 3. Proceed

Once loaded, go all the way to the very bottom of your custom_functions.php and paste the following code:

// ---------- CUSTOM FEATURE BOX
function custom_feature_box() { 
if (is_front_page()) { ?>
	<!-- START HTML - FRONT PAGE OF YOUR BLOG OR YOUR SITE'S FRONT PAGE IF YOU USE A CUSTOM PAGE FOR THE HOMEPAGE -->

	<!-- END HTML -->
<?php }

elseif (is_home()) { ?>
	<!-- START HTML - IF YOU DO USE A CUSTOM HOMEPAGE, THIS IS THE MAIN BLOG PAGE -->

	<!-- END HTML -->
<?php }

elseif (is_page()) { ?>
	<!-- START HTML - ALL INDIVIDUAL PAGES -->

	<!-- END HTML -->
<?php }

elseif (is_single()) { ?>
	<!-- START HTML - ALL INDIVIDUAL POSTS -->

	<!-- END HTML -->
<?php }

else { ?>
	<!-- START HTML - EVERYWHERE ELSE... LIKE ARCHIVES, SEARCH RESULTS, ETC. -->

	<!-- END HTML -->
<?php } 
}
add_action('thesis_hook_feature_box','custom_feature_box');

That code includes a lot of fluff for instructional purposes. Feel free to slim it down if you are comfortable.

Let’s break it down

None of the following code should stand alone in your custom_functions.php file. This is simply to explain the structure. The full code was displayed above in its entirety.

The first line is nothing but a comment telling you what’s coming next in your code:

// ---------- CUSTOM FEATURE BOX

Next up, we’re creating the function called “custom_feature_box” with the following code:

function custom_feature_box() { 

}
add_action('thesis_hook_feature_box','custom_feature_box');

This code is like the frame for your function. It creates the function that will “hold” your content. Then, in the last line, you are adding your new function to a certain part of Thesis using the hook “thesis_hook_feature_box.”

Now, all you have to do is put a picture in it (get it?). In other words, the rest of the code is inside of the previous code.

if/else Statement

Basically, you’re going to say (through PHP), “If this particular web page loads, display this content in my Feature Box. If that particular web page loads, display that content in my Feature Box. If any other page loads besides the previous two, display this content in my Feature Box.”

Let’s take a look:

if (is_front_page()) { ?>
	<!-- START HTML - FRONT PAGE OF YOUR BLOG OR YOUR SITE'S FRONT PAGE IF YOU USE A CUSTOM PAGE FOR THE HOMEPAGE -->

	<!-- END HTML -->
<?php }

elseif (is_home()) { ?>
	<!-- START HTML - IF YOU DO USE A CUSTOM HOMEPAGE, THIS IS THE MAIN BLOG PAGE -->

	<!-- END HTML -->
<?php }

elseif (is_page()) { ?>
	<!-- START HTML - ALL INDIVIDUAL PAGES -->

	<!-- END HTML -->
<?php }

elseif (is_single()) { ?>
	<!-- START HTML - ALL INDIVIDUAL POSTS -->

	<!-- END HTML -->
<?php }

else { ?>
	<!-- START HTML - EVERYWHERE ELSE... LIKE ARCHIVES, SEARCH RESULTS, ETC. -->

	<!-- END HTML -->
<?php }

Each statement in the content above includes an HTML comment explaining what that particular section represents. Here’s a breakdown of each chunk of code:

if (is_front_page()) { ?>
	<!-- START HTML - FRONT PAGE OF YOUR BLOG OR YOUR SITE'S FRONT PAGE IF YOU USE A CUSTOM PAGE FOR THE HOMEPAGE -->

	<!-- END HTML -->
<?php }

The front page of your blog is just that… the front page. If your homepage is a blog, this code will target the feature box on that page. However, if you are using a custom template for your homepage, that page will be targeted.

Next up:

elseif (is_home()) { ?>
	<!-- START HTML - IF YOU DO USE A CUSTOM HOMEPAGE, THIS IS THE MAIN BLOG PAGE -->

	<!-- END HTML -->
<?php }

If you are, in fact, using a custom layout for your homepage, this code will now represent your main blog page. It represents the “home” of your blog content.

Moving on:

elseif (is_page()) { ?>
	<!-- START HTML - ALL INDIVIDUAL PAGES -->

	<!-- END HTML -->
<?php }

Pages created through the dashboard option will be targeted by this section. Every single page will have this Feature Box content. See the bottom of this article for more options.

Still not done:

elseif (is_single()) { ?>
	<!-- START HTML - ALL INDIVIDUAL POSTS -->

	<!-- END HTML -->
<?php }

Individual blog posts will be targeted by this section. Every single post will have this Feature Box content. See the bottom of this article for more options.

One more:

else { ?>
	<!-- START HTML - EVERYWHERE ELSE... LIKE ARCHIVES, SEARCH RESULTS, ETC. -->

	<!-- END HTML -->
<?php }

Every other web page on your blog will display the Feature Box content in this section. This includes search result pages, archives, and other random web pages in WordPress.

It’s just that easy.

Targeting Specific Pages/Posts

Is there a certain page or post that you’d like to have a custom message on?

This can be great for high traffic pages or posts that are seen more often than others.

Here’s how you do it.

When you are creating (or editing) a page or post, you can grab the Post ID to target that particular page or post.

For example, if you are creating a contact page, here’s what you will see once you save the draft or publish the post:

Do you see where the red arrow is pointing?

Hover over that link but do not click it. When you over, most modern web browsers will allow you to preview the URL in the bottom right or the bottom left corner of the browser.

That URL will look something like this:

http://sdavism … post.php?post=202&actio … ost_name

The red part is your Post ID! Remember that number.

Now, let’s add a new chunk of PHP to our new function to specify the new contact page.

elseif (is_page(202)) { ?>
	<!-- START HTML - CONTACT PAGE -->

	<!-- END HTML -->
<?php }

The only difference in this code and the other is_page() code is that page 202 is specified here. You will want to have your new code pasted directly above the original is_page() section in your statement… like this:

elseif (is_page(202)) { ?>
	<!-- START HTML - CONTACT PAGE -->

	<!-- END HTML -->
<?php }

elseif (is_page()) { ?>
	<!-- START HTML - ALL INDIVIDUAL PAGES -->

	<!-- END HTML -->
<?php }

Now, every page will have the same Feature Box content except for your contact page, which will display the content you just created.

You can do this with pages and posts – is_single(). Likewise, you can do this as many times as you’d like.

Targeting Multiple Pages or Posts at Once

We can take this thing one step further.

What if you had three posts on your blog that you wanted to share Feature Box content? Just write the code three times!

I’m joking… no need for that.

Instead, you would follow the same exact format as above except you would separate the IDs with a comma which creates an array.

elseif (is_single(array(x,y,z))) { ?>
	<!-- START HTML - THREE SPECIFIC POSTS -->

	<!-- END HTML -->
<?php }

Now, every post will display the same Feature Box content except for the single post you specified before and the three specified in your new array. Of course, you would replace x, y, and z with IDs. You can, however, let them stay there as a place holder until use, though.

Are you starting to get the feel of why I never use the default options anymore? ;)

Hey! Never do this without backing up your custom_functions.php file first. You hear me?

That’s all there is to it, folks. Play around with these options and get the most out of the Thesis Feature Box. It’s not just there to look pretty, you know?

20 Comments:
    •  Not at all. You just won’t have any content in your Feature Boxes as there is no content in the code above. At that point, all Feature Box content control will take place in the custom_functions.php file. So, always at least copy and paste the entire contents of that file into another plain text editor… or just download it.

  1. Hey Sean, I was thinking of giving this a shot.

    But I just have one question: is the HTML code that I’ll be pasting in there the same as what I paste in, say, the chronicl ‘feature box’ section in the chronicl options area?

    Or does this require more ‘raw’ HTML code? 

    •  Hey, Brandon.

      What you get from the article above can take the place of your Chronicl Feature Box. I don’t use it at all… just my code above. Both of them can show one on top of the other and still look totally normal but there’s really no point.

      If you use the code above, everything can be controlled from the custom_functions.php file and you can pick which page/post will display what.

      If you use the Chronicl Feature Box option, it will display based on what you’ve selected in Dashboard => Thesis => Design Options => Feature Box… no matter what.

      So both are great options. What I’ve pasted above, though, just gives you full control.

      • That was great, Sean…thanks.

        What I was wondering was the HTML code that goes within the function. Where it says, “start HTML code”.

        Do you think I can just paste what I already have in the chronicl feature box options or do I have to be more specific with the code?

        Thanks again sean

        •  Oh, definitely! You can snatch it from over there and paste it underneath one of the “Start HTML” lines, above “End HTML.” That’s just my visual guide and can be erased if you want.

  2. Thanks Sean! that helped alot. My site’s look alright now :)

    I have one more question: How do I target specific ‘Category’ pages?

    I can’t seem to find the specific ‘id number’ associated with them. 

  3. Great tutorial. Thanks for sharing. Can you please share URLs of Thesis sites which have followed these instructions? Thanks.

    • Well, every single one of mine have this code. Right here on SDavis Creations, you can see the feature box information change from page to page. SuccessOnMyMind.com is another one of my sites that uses it. Almost every page is different there. YouSetthePace.com does as well.

      Just so you know, though, unless a person is willing to let you see his or her custom_functions.php file, this is really not a good question to ask. There’s no other way to prove that a Thesis site uses the code. All you can really do is have an understanding of PHP and know it will work just by looking at it. If not, you’re pretty much on your own.

      PHP doesn’t work in a manner that will allow a person to provide a list like that. No matter what, PHP will display as HTML if you view the page source.

  4. Would it be possible to generate the html by making a page in site and then link the php to that page? This would keep the formatting the page and text work completely outside the custom php file.

    • or is there a still better alternative that I just didn’t catch?

    •  I’m sure there’s a way to do that with PHP but I don’t know how great of an idea it would be from our standpoint. I think that would require a decent amount of coding to get up and running like that. Kolakube’s Marketer’s Delight 2 has a feature designed to allow different Feature Box content from the create page screen, but again, you’d have to have a full blown skin to get that.

  5. nice post Sean! not sure if is_single(x,y,z) will work for multiple posts. At least for pages, it works as is_page(array(x,y,z))  
    So, I am assuming that “array” is required in case of posts as well. :)

  6. Hey man,

    I like the email signup box you have after your posts.

    I have thesis, how do I go about creating one of these?

    Thanks!

    - Sean

Leave a Reply

Your email address will not be published. Required fields are marked *

*