Thesis Theme

Displaying Content Only on Specific / Certain Pages with Thesis for WordPress

Thesis' versatile hooks system allows straightforward display of content on specific pages.

The hooks system in the Thesis Theme for WordPress makes it very easy to move content around on your website  and display it where you like.  What if you are are looking to display content only on certain pages though?  Say you have an “About Us” page on which you’d like to display some custom text, how could you display that?

Dynamic content can be implemented through the Thesis custom_functions.php file. We use it on our site to display different content on the sidebar for our blog than we do on the other pages on the Collaboration 133 site.

To display a custom text box that can accommodate HTML and CSS on your About Us page, simply paste the below code into custom_functions.php

// Custom text box on specific pages
function custom_text_box() {
if (is_page('about')) {
?>
<div style="width: 400px; font-family: arial; font-size: 16px; font-weight: bold; color: #2361A1; padding: 12px; border: 3px solid #ccc; margin-bottom: 20px;">
Isn't this a nice custom function that only appears on the About page?
</div>
<?php
}
}
add_action('thesis_hook_before_headline','custom_text_box');

Notes:
1) The CSS code on line 4 can be modified to change the appearance of the custom text / html box or you can define an ID for the <div> and style the box in your stylesheet.

2) Line 3 defines the page on which the custom content will be shown and there are a number of different conditional tags that can be used. All of the conditional tags available are listed on this page in the WordPress Codex lists all the conditional tags available. Below are a few examples of common uses and constructions for your reference:

  • is_front_page() This will apply the function to your site’s home page, whether it’s a page full of blog posts or a static page.
  • is_home() This will apply the function to your site’s home page only if it’s a blog page—not if it’s a static page. If you are using a static home page, is_home() will apply to whatever page you selected to be your blog page.
  • is_page(’23’) This will apply the function to a static page with an ID of 23. If you’ve set your permalinks so that the page ID doesn’t show up in the URL, you can determine what it is by going to the WordPress Pages screen and mousing over the page name. The URL will show up in the status bar at the bottom left of the screen with the post-ID number in it.
  • Note: You can identify pages in a conditional statement using either the ID number, the page title, or the page slug, which is the last part of the URL when you’re not using default permalinks. For example, if the URL is www.techforluddites.com/products, then “products” is the slug, and the tag would be is_page(‘products’).

  • is_single(‘5’) This will apply to the individual post page with the ID of 5. You can find the ID number by mousing over the post title in the Posts screen in WordPress.
  • !is_page(’23’) The exclamation mark means “not” so this tag means the function would apply to any page (including pages with multiple posts on them) except for the one with the ID of 23.
  • is_page(‘about’) || is_page(‘contact’) The double vertical bars mean “or” so this says to apply the function if it’s the About page or the Contact page (which means it will apply to both of them).
  • is_single() && !in_category(‘business’) Here’s where you can see how you can build more complex conditional statements. The && represents “and”, so this is saying to apply the function to any page that is a single post page and that is NOT in the business category. In other words, every individual post page unless that post is in the Business category.
  • Note: There’s a difference between is_category(‘business’) and in_category(‘business’). The former applies only to the actual archive page for Business, which will list all the posts from that category. The latter applies to any post that you’ve assigned to the Business category.

If you visit the WordPress Codex page, you will see that there are many more combinations available, but this short list should allow you to do a lot of customization to your site. If you have any questions about or problems with implementing specific conditional statements, please feel free to contact us about them and we’ll be happy to help figure them out. Further information is also available here.

Leave a Reply

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