您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取当前Post ID函数:get_the_ID

时间:2024-03-11

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()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 sex.cyou


Whatsapp
Powered by RRZCMS