WordPress:Function Reference/get post

来自站长百科
Xxf3325讨论 | 贡献2008年7月22日 (二) 17:35的版本
跳转至: 导航、​ 搜索

描述

得到文章ID并且返回那篇文章的数据库记录。你可以通过$output参数规定,你希望结果以什么样的方式返回。

用法

%%%<?php get_post($post, $output); ?> %%%

例子

得到一篇文章ID为7的文章标题:

%%%<?php $my_id = 7; $post_id_7 = get_post($my_id); $title = $post_id_7->post_title; ?> %%%


此外,规定$output参数:

%%%<?php $my_id = 7; $post_id_7 = get_post($my_id, ARRAY_A); $title = $post_id_7['post_title']; ?> %%%


%%%<?php

    1. Correct: pass a dummy variable as post_id

$the_post = & get_post( $dummy_id = 7 );


    1. 不正确的:字面意思上的整数作为post_id

$the_post = & get_post( 7 ); // 致命错误: '只有变量可以作为 reference传递' 或者 '不能够通过reference传递参数1' ?>%%%

参数

模板:参数

模板:参数

返回

返回的field是:

ID
(integer) 文章 ID
post_author
(integer) 文章作者的ID
post_date
(string) 文章发表的日期(YYYY-MM-DD HH:MM:SS)
post_date_gmt
(string) 文章发表的格林尼治时间(YYYY-MM-DD HH:MM:SS)
post_content
(string) 文章的内容
post_title
(string) 文章的标题


post_category
(integer)文章的类别ID。从WordPress2.1开始,这个ID通过是0(零)。要决定一篇文章的类别,请使用get_the_category()。
post_excerpt
(string) 文章摘录
post_status
(string) 文章级别(publish|draft|private|static|object|attachment|inherit|future)
comment_status
(string) 评论级别(open|closed|registered_only)
ping_status
(string) pingback/trackback 级别(open|closed)
post_password
(string) 文章密码
post_name
(string) 文章的URL slug
to_ping
(string) 将要ping 的URLs
pinged
(string) 已经ping的URLs
post_modified
(string) 文章最后更改的时间(YYYY-MM-DD HH:MM:SS)
post_modified_gmt
(string) 文章最后更改的格林尼治时间 (YYYY-MM-DD HH:MM:SS)
post_content_filtered
(string)
post_parent
(integer) 母文章ID (对于附属,等等)
guid
(string)文章的permalink
menu_order
(integer)
post_type
(string) (post|page|attachment)
post_mime_type
(string) Mime Type (对于附属,等等)
comment_count
(integer)评论的数目

参考

get_post method not working NB: "这个话题不接受新的回复。"

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.