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

wordpress獲取最新發表文章函數: wp_get_recent_posts()

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

說明

wordpress 按發表時間檢索數據庫中的最新發表文章。默認檢索最近十篇文章。

用法

  1. <?php?wp_get_recent_posts(?$args?)??>

參數

  1. <?php
  2. $args?=?array(
  3. ???????????'numberposts'?=>?10,
  4. ????'offset'?=>?0,
  5. ????'category'?=>?0,
  6. ????'orderby'?=>?'post_date',
  7. ????'order'?=>?'DESC',
  8. ????'include'?=>?,
  9. ????'exclude'?=>?,
  10. ????'meta_key'?=>?,
  11. ????'meta_value'?=>,
  12. ????'post_type'?=>?'post',
  13. ????'post_status'?=>?'draft,?publish,?future,?pending,?private',
  14. ????'suppress_filters'?=>?true
  15. ????);
  16. ?>

或者傳入一個(整數)將獲取的文章數量

默認值: 10

返回的值

(數組) 跟 get_posts 不同get_posts 返回的是 objects

文章列表

示例

1.返回最新的10篇文章

  1. <h2>Recent Posts</h2>  
  2. <ul>  
  3. <?php  
  4.  $recent_posts = wp_get_recent_posts();  
  5.  foreach$recent_posts as $recent ){  
  6.   echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';  
  7.  }  
  8. ?>  
  9. </ul>  

2.返回最新的5篇文章

  1. <h2>Recent?Posts</h2>
  2. <ul>
  3. <?php
  4. ?$args?=?array(?'numberposts'?=>?'5'?);
  5. ?$recent_posts?=?wp_get_recent_posts(?$args?);
  6. ?foreach(?$recent_posts?as?$recent?){
  7. ??echo?'<li><a?href="'?.?get_permalink($recent["ID"])?.?'"?title="Look?'.esc_attr($recent["post_title"]).'"?>'?.???$recent["post_title"].'</a>?</li>?';
  8. ?}
  9. ?>
  10. </ul>

修改記錄

自1.1.0版本后

源文件

wp_get_recent_posts() is located in wp-includes/post.php.

  1. /**
  2. ?*?Retrieve?number?of?recent?posts.
  3. ?*
  4. ?*?@since?1.0.0
  5. ?*?@uses?wp_parse_args()
  6. ?*?@uses?get_posts()
  7. ?*
  8. ?*?@param?string?$deprecated?Deprecated.
  9. ?*?@param?array?$args?Optional.?Overrides?defaults.
  10. ?*?@param?string?$output?Optional.
  11. ?*?@return?unknown.
  12. ?*/
  13. function?wp_get_recent_posts(?$args?=?array(),?$output?=?ARRAY_A?)?{
  14. ?if?(?is_numeric(?$args?)?)?{
  15. ??_deprecated_argument(?__FUNCTION__,?'3.1',?__(?'Passing?an?integer?number?of?posts?is?deprecated.?Pass?an?array?of?arguments?instead.'?)?);
  16. ??$args?=?array(?'numberposts'?=>?absint(?$args?)?);
  17. ?}
  18. ?//?Set?default?arguments
  19. ?$defaults?=?array(
  20. ??'numberposts'?=>?10,?'offset'?=>?0,
  21. ??'category'?=>?0,?'orderby'?=>?'post_date',
  22. ??'order'?=>?'DESC',?'include'?=>?'',
  23. ??'exclude'?=>?'',?'meta_key'?=>?'',
  24. ??'meta_value'?=>'',?'post_type'?=>?'post',?'post_status'?=>?'draft,?publish,?future,?pending,?private',
  25. ??'suppress_filters'?=>?true
  26. ?);
  27. ?$r?=?wp_parse_args(?$args,?$defaults?);
  28. ?$results?=?get_posts(?$r?);
  29. ?//?Backward?compatibility.?Prior?to?3.1?expected?posts?to?be?returned?in?array
  30. ?if?(?ARRAY_A?==?$output?){
  31. ??foreach(?$results?as?$key?=>?$result?)?{
  32. ???$results[$key]?=?get_object_vars(?$result?);
  33. ??}
  34. ??return?$results???$results?:?array();
  35. ?}
  36. ?return?$results???$results?:?false;
  37. }
3 0

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

正版主題商店

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

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

服務熱線

wordpress建站咨詢