wordpress中is_sticky()判别文章能否置顶的参数与用法

【阐明】

反省以后文章能否置顶。前往值TRUE 或许 FALSE.

【用法】


<?php is_sticky($post_ID); ?>

【参数】
$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复制内容到剪贴板

  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)中参数生效”的成绩,斧正本人对wordpress is_sticky($post_id)办法的谬误了解。

以上就是安达网络工作室关于《wordpress中is_sticky()判断文章是否置顶的参数与用法》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: wordpress is_sticky 置顶
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress中创立用户角色的相干PHP函数应用详解

WordPress 默许有 “订阅者”、“投稿者”、“作者”、“编辑” 和 “治理员” 五个用户角色,权限由低到高...

Wordpress中上一篇与下一篇性能代码

本文实例讲述了Wordpress中上一篇与下一篇性能代码。分享给大家供大家参考。详细如下: 很多WordPress给文章...

简略理解WordPress开发中update_option()函数的用法

函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...

WordPress搜寻后果按阅读量排序的完成办法

默许状况下,WordPress 存档页面或搜寻后果页面中的日志陈列秩序是依照重新到旧来陈列的,这里咱们暂且不论...

详解WordPress中增加和执举动作的函数应用办法

add_action()(增加举措) add_action() 函数用来挂载一个函数到举措钩子上。 用法 add_action( $tag, $fu...

详解WordPress中简码格局标签编写的根本办法

WordPress 简码是一品种似于论坛标签的货色,格局相似于把尖括号换成中括号的 Html 标签。简码很多人叫做短...

需求提交

客服服务