how to obtain the post id in wordpress templates
i know in wordpress loop
the_ID();
w开发者_StackOverflowill output the post id, if i want to set $var = the post id; what should i do?
Instead of the_ID(), which echoes its result, use the function get_the_ID(), which returns the ID and you can assing it to a variable to be used in your php script.
$postid = get_the_ID();
/* do here what you need with $postid.. */
FYI, there's a nice official repository of WP APIs, the CODEX
精彩评论