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

wordpress獲取文章類型函數:get_post_type()

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

說明

檢索當前文章或給定文章的文章類型。

用法

  1. <?php?get_post_type(?$post?)??>

參數

$post

(混合)(可選)文章對象或文章ID。

默認值: false

返回的值

(布爾型| 字符)

返回文章類型,出錯時返回false。

示例

  1. <?php
  2. $post_type?=get_post_type(36);
  3. //假設id為36的文章類型為附件類型attachment
  4. echo?$post_type;
  5. //打印出attachment
  6. ?>

注釋

用法:$posts 日志循環的全局變量

修改記錄

自2.1.0版本后

源文件

get_post_type() 位于wp-includes/post.php中

  1. /** 
  2. * Retrieve the post type of the current post or of a given post. 
  3. * 
  4. * @since 2.1.0 
  5. * 
  6. * @uses $post The Loop current post global 
  7. * 
  8. * @param mixed $the_post Optional. Post object or post ID. 
  9. * @return bool|string post type or false on failure. 
  10. */  
  11. function get_post_type( $the_post = false ) {  
  12. global $post;  
  13.   
  14. if ( false === $the_post )  
  15. $the_post = $post;  
  16. elseif ( is_numeric($the_post) )  
  17. $the_post = get_post($the_post);  
  18.   
  19. if ( is_object($the_post) )  
  20. return $the_post->post_type;//返回文章的類型post_type  
  21.   
  22. return false;  
  23. }  
0 0

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

正版主題商店

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

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

服務熱線

wordpress建站咨詢