女武神的终末第三季免费观看,国产精品va无码二区,欧美日韩在线视频观看,国产在线观看网站

wordpress按文章編號(hào)檢索某篇文章函數(shù): wp_get_single_post()

2016-10-16 wordpress函數(shù)
  • 文章介紹
  • 快速入門
  • 評(píng)價(jià)&建議

說(shuō)明

wordpress 按文章編號(hào)檢索某篇文章。

用法

  1. <?php wp_get_single_post( $postid$mode ) ?>  

參數(shù)

$postid

(整數(shù))(可選)文章編號(hào)

默認(rèn)值: 0

$mode

(字符)(可選)如何返回結(jié)果。結(jié)果應(yīng)為常量:OBJECT, ARRAY_N, or ARRAY_A

默認(rèn)值:OBJECT

返回的值(對(duì)象 | 數(shù)組)

文章對(duì)象或數(shù)組,該對(duì)象或數(shù)組所包含的內(nèi)容和信息應(yīng)含有兩個(gè)附加字段(或關(guān)鍵字): ‘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

企業(yè)建站推薦正版商業(yè)主題,國(guó)內(nèi)專業(yè)團(tuán)隊(duì)開發(fā),完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計(jì)幫助1300+客戶成功建站,為站長(zhǎng)提供支持!

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

服務(wù)熱線

wordpress建站咨詢