Hi there,
You could read more about conditional tags here. Remember to hook the wrapper function of is_single after wp_query ran if you are using it in functions.php or give it a priority to run later.
To do this in template files you could create custom query:
$query = new WP_Query( array( 'post_type' => 'post' ) );
You could check the post type in the loop:
if( $query->have_posts() ) {
if( 'post' == $query->post_type ) {
// Do something with single post
}
if( 'page' == $query->post_type ) {
// Do something with single page
}
if( 'book' == $query->get_post_type() ) {
// Do something with book post type
}
}
Or you could create a function and give it a higher priority:
function where_am_i()
{
if (is_single()) {
// Do something with single post
}
if (is_page()) {
// Do something with single page
}
}
add_action('the_post', 'where_am_i', 135);
You could create a post object and check by ID:
function where_am_i($post_ID)
{
global $post;
if ($post->ID == $post_ID) {
// Do something here
}
}
add_action('the_post', 'where_am_i', 135);