![]() |
wordpress 通过get_the_ID和the_ID函数获取文章ID
get_the_ID() 返回当前文章的ID号,此标签必须在主循环里。
用法:<?php get_the_ID(); ?> 示例: eg1: <?php $id = get_the_ID(); $dropdown = "<select name='dropdown-".$id."' >"; $dropdown.="<option id='option1-".$id."'>Option 1</option>"; $dropdown .= "</select>"; echo $dropdown; ?> eg2: <?php echo '<input type="hidden" name="activepost" id="activepost" value="'.get_the_ID().'" />'; ?> the_ID() 输出当前文章的ID号,此标签必须在主循环里。 用法:<?php the_ID(); ?> 示例: eg1: <p>Post Number:<?php the_ID(); ?></p> eg2: <h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3> 源文件:get_the_ID()和the_ID() 都在 wp-includes/post-template.php文件. |
| All times are GMT +8. The time now is 12:25 AM. |
Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.