星联网络专注帝国CMS二次功能插件开发-精品网站模板站长代码素材

  • 最近更新
  • 模板:33
  • 记录:12641|
  • 插件:52|
  • 工具:4|
  • 代码:8|
  • 评论:0

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

前言

本文重点解决wodpess中is_sicky()判断文章是否置顶的参数与用法问题,希望能够帮助到你

【说明】

检查当前文章是否置顶。返回值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. }  

本网刊登的文章均仅代表作者个人观点,并不代表本网立场。文中的论述和观点,敬请读者注意判断。

本文地址:http://www.xlkjgs.com/notes/web/3376.html

以上内容由本站整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

星联网络

星联网络是中国最具实战的互联网创业者的知识服务商,这里有互联网行业动态,网络推广,SEO优化,SEM优化,ESC配置,行业经验分型,互联网项目,微信营销、淘宝客赚钱、新媒体营销、京东运营、跨境电商等众多互联网营销知识分享

站长运营站长必备网站运营之道才能长久发展