久青草国产观看在线视频,在线观看欧美日女,777毛片,亚洲国产精品99久久久久久久

wordpress按文章編號檢索某篇文章函數: wp_get_single_post()

2016-10-16 wordpress函數
  • 文章介紹
  • 快速入門
  • 評價&建議

說明

wordpress 按文章編號檢索某篇文章。

用法

  1. <?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.

  1. /** 
  2.  * Retrieve a single post, based on post ID. 
  3.  * 
  4.  * Has categories in 'post_category' property or key. Has tags in 'tags_input' 
  5.  * property or key. 
  6.  * 
  7.  * @since 1.0.0 
  8.  * 
  9.  * @param int $postid Post ID. 
  10.  * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. 
  11.  * @return object|array Post object or array holding post contents and information 
  12.  */  
  13. function wp_get_single_post($postid = 0, $mode = OBJECT) {  
  14.  $postid = (int) $postid;  
  15.   
  16.  $post = get_post($postid$mode);  
  17.   
  18.  if (  
  19.   ( OBJECT == $mode && emptyempty$post->ID ) ) ||  
  20.   ( OBJECT != $mode && emptyempty$post['ID'] ) )  
  21.  )  
  22.   return ( OBJECT == $mode ? null : array() );  
  23.   
  24.  // Set categories and tags  
  25.  if ( $mode == OBJECT ) {  
  26.   $post->post_category = array();  
  27.   if ( is_object_in_taxonomy($post->post_type, 'category') )  
  28.    $post->post_category = wp_get_post_categories($postid);  
  29.   $post->tags_input = array();  
  30.   if ( is_object_in_taxonomy($post->post_type, 'post_tag') )  
  31.    $post->tags_input = wp_get_post_tags($postidarray('fields' => 'names'));  
  32.  } else {  
  33.   $post['post_category'] = array();  
  34.   if ( is_object_in_taxonomy($post['post_type'], 'category') )  
  35.    $post['post_category'] = wp_get_post_categories($postid);  
  36.   $post['tags_input'] = array();  
  37.   if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )  
  38.    $post['tags_input'] = wp_get_post_tags($postidarray('fields' => 'names'));  
  39.  }  
  40.   
  41.  return $post;  
  42. }  
0 0

企業建站推薦正版商業主題,國內專業團隊開發,完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計幫助1300+客戶成功建站,為站長提供支持!

立刻開啟你的建站之旅
QQ在線客服

服務熱線

wordpress建站咨詢