WordPress获取当前Post ID函数:get_the_ID

文 / @WordPress主题

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

相关函数:

  • get_post()
  • wp_get_archives()
  • get_post_comments_feed_link()
  • the_ID()
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。