开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜