[wp-hackers] Finding post ID while in header

Mark Jaquith mark.wordpress at txfx.net
Tue Mar 21 21:00:21 GMT 2006

On Mar 21, 2006, at 3:18 PM, CaptSolo wrote:

> Could you suggest how to find out what the post ID is while in header?
> E.g., how to display a post ID (if this is a single post page) within
> HTML comments.

<?php if ( is_single() ) echo $posts[0]->ID; ?>


<?php if ( is_single() ) { $post = $posts[0]; the_ID(); } ?>

The second one will let you use most "in the loop" functions  
prematurely (i.e. before the loop) and doesn't, in my experience,  
interfere with the loop.  But if all you need to do is echo the ID,  
I'd go with the first one.

Mark Jaquith

More information about the wp-hackers mailing list