WordPress函数the_post()获取当前文章的所有信息

描述:

获取当前文章的所有信息

the_post()函数调用$wp_query->the_post()成员函数前移循环计数器,并且创建一个全局变量$post(不是$posts),把当前的post的所有信息都填进这个$post变量中,以备接下来使用。

用法:

<?php the_post(); ?>

示例:

<?php
if ( have_posts() ) {
	while ( have_posts() ) {

		the_post(); ?>

		<h2><?php the_title(); ?></h2>

		<?php the_content(); ?>

	<?php }
}
?>

源文件:

/**
 * Iterate the post index in the loop.
 *
 * @since 1.5.0
 *
 * @global WP_Query $wp_query
 */
function the_post() {
	global $wp_query;
	$wp_query->the_post();
}