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文章中微信打赏性能的2种完成办法

本文实例讲述了WORDPRESS文章中微信打赏性能的2种完成办法。分享给大家供大家参考,详细如下: 打赏性能性能...

wordpress开发之插件开发初识(wordpress插件开发根底)

首先,你要在wp-content/plugins/下建设一个文件夹,文件夹的名字最好只由字母、数字、&ldquo;-&rdquo;和下...

多个WordPress站点应用同一数据库的办法

尚未装置WordPress 在初始配置WordPress之前,将wp-config.php中的$table_prefix值(默许为wp_)修正为所需求...

如何设置WordPress图片防盗链办法 推荐

假如您的博客有很多很多图片,空间又有流量限度,那么避免他人盗取本人的图片链接应该说是势在必行了,由于...

wordpress中短代码生效处理方法

在以前的代码中,咱们仅仅应用add_shortcode函数来把短代码注册到wordpress中,在文章页应用the_content来显...

在WordPress的文章编辑器中设置默许内容的办法

很多时分咱们需求在给 WordPress 文章编辑器设置默许内容,比方把罕用的扫尾或许文章留意事项放出来,本文就...

需求提交

客服服务