
使用XAMPP本地搭建WordPress网站图文教程
stick_post ( $post_id )
WordPress中的stick_post函数是用来把一个文章粘在博客首页的顶部的: 当一个文章被”粘”住时,它就会保持在博客首页的顶部,不管它是什么时候发布的,直到它被手动”解粘”。
使一个文章置顶。
置顶文章应该显示在首页的顶部。
function stick_post( $post_id ) { $post_id = (int) $post_id; $stickies = get_option( 'sticky_posts' ); $updated = false; if ( ! is_array( $stickies ) ) { $stickies = array(); } else { $stickies = array_unique( array_map( 'intval', $stickies ) ); } if ( ! in_array( $post_id, $stickies, true ) ) { $stickies[] = $post_id; $updated = update_option( 'sticky_posts', array_values( $stickies ) ); } if ( $updated ) { /** * Fires once a post has been added to the sticky list. * * @since 4.6.0 * * @param int $post_id ID of the post that was stuck. */ do_action( 'post_stuck', $post_id ); } }