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提醒require_once() Failed opening required的处理办法

本文实例讲述了WordPress提醒require_once() Failed opening required的处理办法。 一、成绩: 明天进我的w...

Wordpress不必插件的SEO优化办法分享

复制代码代码如下:<title><?php if ( is_home() ) { ?><?php bloginfo('name'); ?> | <?php bloginfo('...

以WordPress为例解说jQuery丑化页面Title的办法

这里选取的例子,便是 WordPress 中比拟有名的丑化超链接Title成果,普通的 title 成果是把鼠标放到 a 元素...

WordPress中创立用户角色的相干PHP函数应用详解

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

WordPress 增加Meta Box的办法

置信很多站长都晓得并且曾经在应用WordPress自定义字段,很多插件也应用了这一性能。 自定义字段是一个十分...

WordPress博客SEO愈加完满的6个技巧

wordpress是十分不错的博客顺序,也是很多博客喜好者所喜爱的建站顺序之一,wordpress不只仅模版丰厚,而且...

需求提交

客服服务

亿鸽在线客服系统