Hi, you can use the get_post_type() function. e.g.
if ( get_post_type() == 'book' ) { ... }
Here’s a handy page to bookmark: http://codex.wordpress.org/Conditional_Tags
🙂
thanks, in more detail and in words I am trying to say if it is NOT a single page excluding the custom post types
so my weak attempt was:
if ( ! is_single() but somehow exclude CPT single pages )
I also tried the blog page ID in the post parent conditional but it did not work:
if ( ! $post->post_parent == '36' )
Does this mean you only want to target Posts, but not CPTs? You can also use get_post_type()
for regular Posts.
if ( get_post_type() == 'post' ) {
// this code only runs for Posts
}
Or combine them
if ( get_post_type() == 'post' || get_post_type() == 'book' ) {
// this code only runs is the current post is a regular Post or Book CPT
}
Hint: regular ‘ol Posts are a CPT too (“Posts” CPT)
This seems to target even the posts of the CPT, just wondering how I can separate btw/ blog single post pages and CPT single post pages.
if ( get_post_type() == 'post' ) {
// this code only runs for Posts
}
OK not sure if this is a workaround, but I excluded the single pages but then added in the CPT single pages. So basically a banner image shows for all the CPT single pages but not the blog post single pages.
if ( ! is_single() || get_post_type() == 'landing_pages' ) {
// Show banner images for CPT single pages but not blog post single pages
}
Duh, can’t believe I stumbled there, if anyone has cleaner code please let me know and thanks for the help blogjunkie
Doesn’t it work if you just do this?
if ( get_post_type() == 'landing_pages' ) {}
That will only target landing_pages CPT single pages, not regular Post single pages
I had to exclude the single pages of the blog post otherwise the custom banners I was building were showing up on the blog single pages which I did not want.