說明
wordpress 按文章編號檢索某篇文章。
用法
- <?php wp_get_single_post( $postid, $mode ) ?>
參數
$postid
(整數)(可選)文章編號
默認值: 0
$mode
(字符)(可選)如何返回結果。結果應為常量:OBJECT, ARRAY_N, or ARRAY_A
默認值:OBJECT
返回的值(對象 | 數組)
文章對象或數組,該對象或數組所包含的內容和信息應含有兩個附加字段(或關鍵字): ‘post_category’ 和 ‘tags_input’。
示例
用法:get_post()
用法:wp_get_post_categories()
用法:wp_get_post_tags()
修改記錄
自1.1.0版本后
源文件
wp_get_single_post() is located in wp-includes/post.php.
-
-
-
-
-
-
-
-
-
-
-
-
- function wp_get_single_post($postid = 0, $mode = OBJECT) {
- $postid = (int) $postid;
-
- $post = get_post($postid, $mode);
-
- if (
- ( OBJECT == $mode && emptyempty( $post->ID ) ) ||
- ( OBJECT != $mode && emptyempty( $post['ID'] ) )
- )
- return ( OBJECT == $mode ? null : array() );
-
-
- if ( $mode == OBJECT ) {
- $post->post_category = array();
- if ( is_object_in_taxonomy($post->post_type, 'category') )
- $post->post_category = wp_get_post_categories($postid);
- $post->tags_input = array();
- if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
- $post->tags_input = wp_get_post_tags($postid, array('fields' => 'names'));
- } else {
- $post['post_category'] = array();
- if ( is_object_in_taxonomy($post['post_type'], 'category') )
- $post['post_category'] = wp_get_post_categories($postid);
- $post['tags_input'] = array();
- if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )
- $post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names'));
- }
-
- return $post;
- }