wordpress函数get_the_ID()和the_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."'>Option1</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>
推荐阅读:
