最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

wordpress中is_sticky()判斷文章是否置頂?shù)膮?shù)與用法

  發(fā)布時間:2015-01-15 19:55:46   作者:佚名   我要評論
這篇文章主要介紹了wordpress中is_sticky()判斷文章是否置頂?shù)膮?shù)與用法,需要的朋友可以參考下

【說明】

檢查當前文章是否置頂。返回值TRUE 或者 FALSE.

【用法】


復制代碼
代碼如下:

<?php is_sticky($post_ID); ?>

【參數(shù)】
$post_ID
(string) (optional) 文章 ID
默認: None
返回值
(boolean)
True,或 false.

【示例】


復制代碼
代碼如下:

is_sticky();
// 任意置頂文章被顯示.</p> <p>is_sticky('17');
// 當ID為17的文章被顯示.

【源文件】

is_sticky() 位于 wp-includes/post.php.

PHP Code復制內(nèi)容到剪貼板
  1. /**  
  2.  * Check if post is sticky.  
  3.  *  
  4.  * Sticky posts should remain at the top of The Loop. If the post ID is not  
  5.  * given, then The Loop ID for the current post will be used.  
  6.  *  
  7.  * @since 2.7.0  
  8.  *  
  9.  * @param int $post_id Optional. Post ID.  
  10.  * @return bool Whether post is sticky.  
  11.  */  
  12. function is_sticky( $post_id = 0 ) {   
  13.  $post_id = absint( $post_id );   
  14.   
  15.  if ( ! $post_id )   
  16.   $post_id = get_the_ID();   
  17.   
  18.  $stickies = get_option( 'sticky_posts' );   
  19.   
  20.  if ( ! is_array$stickies ) )   
  21.   return false;   
  22.   
  23.  if ( in_array( $post_id$stickies ) )   
  24.   return true;   
  25.   
  26.  return false;   
  27. }  


這里要舉例說明的是:

is_sticky(10) 是判斷 $post_id為 10的文章是否是置頂文章,而不是說所有置頂文章中post_id為 10的置頂文章。之所以會有后者錯誤的理解,也是自己看了官方對于 is_sticky($post_id)方法用法文檔比較模糊的介紹,其實細究起來,“所有置頂文章中post_id為 10的置頂文章” 這種判斷也是多余的,直接 $post->id==10 或 get_the_id()==10 判斷當前文章$post_id是否等于10 就好了!


這里還得感謝下友鏈中的tiandi兄在本站中留言中提醒說不存在“is_sticky($post_ID)中參數(shù)失效”的問題,指正自己對wordpress is_sticky($post_id)方法的錯誤理解。

相關文章

最新評論

广饶县| 贡嘎县| 保亭| 来宾市| 鹤庆县| 朝阳区| 白水县| 东源县| 临江市| 定兴县| 交口县| 横山县| 铜梁县| 苍梧县| 阳西县| 汶上县| SHOW| 靖边县| 攀枝花市| 德庆县| 合川市| 北宁市| 汶川县| 萨嘎县| 杂多县| 邢台县| 察隅县| 满洲里市| 榆林市| 股票| 陆河县| 时尚| 稷山县| 张北县| 巴塘县| 三都| 鹤庆县| 南岸区| 鸡东县| 玛纳斯县| 八宿县|