finding whether request is for post, and post id

I need a hook such that when visitor lands on any of the post (not page), I need to record a hit.

How can I find whether the request is for post, and is there any hook to find if the loaded content is post, and if yes, what is post id

Related posts

Leave a Reply

1 comment

  1. something like this will work:

    function record_hit_if_post(){
        global $wp_query;
        if($wp_query->is_single==1)
            // single post's ID:
            // $wp_query->post->ID;
    }
    add_filter('template_redirect', 'record_hit_if_post');