tags:

views:

76

answers:

2

Hi there,

In a previous post (http://stackoverflow.com/questions/1172335/dont-show-this-if-the-url-contains-the-following) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header.

What I didn't take into consideration, was that I don't want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs.

How do I run a bit of code from my header.php if the page I'm looking at is a blog post?

+2  A: 

You would use the Wordpress functions is_single() and is_page.

if(!is_single() && !is_page() && !is_home() && !is_archive())
{
/* This will not display for any post, page, the home page, or an archive.
 You can remove each is statement according to your needs */
}

For only posts, only use is_single, the same for page, home, and archive.

The full listing of is_statements can be found here. Here are some others:

is_home() : Home Page
is_front_page :  Front Page
is_single() :  Single Post
is_admin() : Admin Panel
is_sticky() : Sticky Post
is_page() : Page
is_category
is_tag
is_author
Chacha102
ahhh... thanks for that!!! !is_single did the trick
cosmicbdog
+1  A: 

It's been long since I've played with wordpress but you can achieve a lot with using the conditional tags:

http://codex.wordpress.org/Conditional_Tags

Seems like is_single() might do what you want. Eg:

if (!is_single())
{
    // display div
}
koen
thanks koen. you're right. chacha was just a minute faster
cosmicbdog