the_ID()显示当前文章ID

目录

描述

Displays the numeric ID of the current post. This tag must be within The Loop.

Note: This function displays the ID of the post, to return the ID use get_the_ID().

the_ID() 描述

用法

 <?php the_ID(); ?> 

the_ID() 用法

参数

This tag has no parameters.

the_ID() 参数

示例

Default Usage

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<p>Post Number: <?php the_ID(); ?></p>

Post Anchor Identifier

Provides a unique anchor identifier to each post:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>

Note: In XHTML, the id attribute must not start with a digit. Since the_ID returns the post ID as numerical data, you should include at least one alphabetical character before using it in an id attribute, as in the example above.

the_ID() 示例

历史

添加于 版本: 0.71

the_ID() 历史

源文件

the_ID() 函数的代码位于 wp-includes/post-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Display the ID of the current item in the WordPress Loop.
 *
 * @since 0.71
 */
function the_ID() {
	echo get_the_ID();
}

the_ID() 源文件

相关