setup_postdata()将文章设置到全局变量$post中

目录

描述

Sets up global post data. Helps to format custom query results for using Template tags.

setup_postdata() fills the global variables $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages, which help many Template Tags work in the current post context. It does not assign the global $post variable, but seems to expect that its argument is a reference to it.

setup_postdata() 描述

用法

<?php 
global $post;
setup_postdata$post ); 
?>

setup_postdata() 用法

参数

$post

(object) (必填) A post object.

默认值: None

You must pass a reference to the global $post variable, otherwise functions like the_title() don't work properly.

For example:

A "clever" formulation:

This will not work:

setup_postdata() 参数

返回值

This function always returns true.

setup_postdata() 返回值

历史

  • 添加于 版本: 1.5.0

setup_postdata() 历史

源文件

setup_postdata() 函数的代码位于 wp-includes/query.php.

setup_postdata() 源文件

相关