With WordPress sometimes you’re not always coding inside The Loop.
Using this little hack allows your widgets to grab the current page ID and could be used to set contextual information which isn’t always easy in WordPress.
Of course it can be used in other parts of your WordPress template too such as footers and asides.
[code language="php"]<?php // Get Current Page ID outside Loop
$post_obj = $wp_query->get_queried_object();
$Page_ID = $post_obj->ID;