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中函数get_term_link的参数设置成绩

为何要用 get_term_link?: 新类型的分类是无奈用 <?php echo get_category_link( $category_id ); ?> 输入...

WordPress退出短代码运转框(运转代码/复制代码/清空代码无插件)

很多冤家可能常常在一些网站上看到相似于&ldquo;运转代码、复制代码、清空代码、另存为代码的动态代码运转框...

WordPress评论治理性能引见

要害字形容:引见 性能 治理 评论 渣滓 审核 能够 网站 Akismet 编辑 如今咱们来看看评论治理性能。评论是...

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

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

WordPress自带thumbnail缩略图性能应用引见

1.增加性能 在function.php中拔出代码 add_theme_support('post-thumbnails'); 拔出之后会在后盾编辑文章的...

WordPress主题构造是如何架构的图文分析

利用弱小的技术,能够把基于WordPress的网站做成各种各样的方式,这除了要求WordPress主题开发人员通晓HTML...

需求提交

客服服务

亿鸽在线客服系统