WordPress获取当前Post ID函数:get_the_ID

WordPress函数get_the_ID一般用在主循环The Loop中,以获取当前Post ID。也可以在文章模板、页面模板中使用,在这些页面即使主循环之外也能获取到当前页面的ID。

get_the_ID()

函数使用示例

<?php
    $id = get_the_ID();
    $dropdown = "<select name='dropdown-".$id."' >";
    $dropdown .= "<option id='option-" . $id ."'>Option</option>";
    $dropdown .= "</select>";
?>

扩展阅读

get_the_ID()函数位于:wp-includes/post-template.php

相关函数:

阿里云