国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

wordpress中is_sticky()置頂文章方法參數與用法

2024-09-07 00:51:45
字體:
來源:轉載
供稿:網友

wordpress is_sticky($post_id) 不帶參數時,主要用來在循環輸出文章列表中時,用來判斷當前$post_id是否是置頂文章,帶參數則是判斷給定的$post_id是否是置頂文章.

說明:檢查當前文章是否置頂,返回值TRUE 或者 FALSE.

用法:<?php is_sticky($post_ID); ?>

參數:$post_ID

(string) (optional) 文章 ID

默認:None

返回值:(boolean) True,或 false.

示例:

  1. is_sticky(); 
  2. // 任意置頂文章被顯示. 
  3. is_sticky('17'); 
  4. // 當ID為17的文章被顯示. 

源文件:

  1. is_sticky() 位于 wp-includes/post.php. 
  2. /** 
  3.  * Check if post is sticky. 
  4.  * 
  5.  * Sticky posts should remain at the top of The Loop. If the post ID is not //開源軟件:Vevb.com 
  6.  * given, then The Loop ID for the current post will be used. 
  7.  * 
  8.  * @since 2.7.0 
  9.  * 
  10.  * @param int $post_id Optional. Post ID. 
  11.  * @return bool Whether post is sticky. 
  12.  */ 
  13. function is_sticky( $post_id = 0 ) { 
  14.  $post_id = absint( $post_id ); 
  15.  if ( ! $post_id ) 
  16.   $post_id = get_the_ID(); 
  17.  $stickies = get_option( 'sticky_posts' ); 
  18.  if ( ! is_array$stickies ) ) 
  19.   return false; 
  20.  if ( in_array( $post_id$stickies ) ) 
  21.   return true; 
  22.  return false; 

這里要舉例說明的是:

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)中參數失效”的問題,指正自己對wordpress is_sticky($post_id)方法的錯誤理解.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新兴县| 乌拉特前旗| 邯郸县| 固始县| 运城市| 盈江县| 西乡县| 东阿县| 朝阳市| 裕民县| 昌邑市| 尉犁县| 禹城市| 德庆县| 屯留县| 邵阳市| 三台县| 白玉县| 湘潭市| 浮山县| 探索| 太仆寺旗| 木兰县| 莆田市| 镇安县| 汶上县| 两当县| 山东省| 双柏县| 秭归县| 永德县| 鸡西市| 灌阳县| 永州市| 汉阴县| 上高县| 昔阳县| 宝清县| 泾阳县| 浮梁县| 鹿邑县|