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 网站转移效劳器操作的两种办法

第一种办法:我的这个博客不断都在网上运转,明天想把它在本地架设一个,包括数据库都和网上的如出一辙。详...

WordPress中查问文章的循环Loop构造及用法剖析

WordPress 上获取文章最重要的就是循环(Loop),现实上循环就是去数据库查问到相应的文章,而后临时贮存到...

wordpress导航如何设置详细该怎样操作

自己wordpress版本:wordpress-3.7.1。 wordpress后盾: 外观==》菜单 左侧咱们能够看到:页面、链接、分类...

wordpress罕用的函数、条件判别以及文件总结

WordPress根本模板文件 一套完好的WordPress模板应至多具备如下文件: style.css : CSS(款式表)文件 index....

WordPress完成的首页幻灯片展现性能示例【附demo源码】

本文实例讲述了WordPress完成的首页幻灯片展现性能。分享给大家供大家参考,详细如下: 关于WordPress拓展性...

WordPress装置应用Flowplayer繁难指南

本文是简略易懂的古代魔法系列文章的第二弹~ 一、Flowplayer简介 FlowPlayer 是一个用Flash开发的在Web上的...

需求提交

客服服务

亿鸽在线客服系统