WordPress获取当前Post ID函数:get_the_ID

2022/07/13
服务器0元试用,首购低至0.6折

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>";
?>
learndash-corporate-training
本文由点金主题网发布 点金主题网提供WordPress主题开发、汉化、安装、优化及网站设计开发服务。 自2010年以来,我们一直在WordPress行业深耕。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注