Make WordPress Core


Ignore:
Timestamp:
08/05/2008 05:48:21 AM (16 years ago)
Author:
ryan
Message:

Sticky Posts, firct cut. see #7457

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r8513 r8546  
    483483        $r['post__not_in'] = preg_split('/[\s,]+/',$r['exclude']);
    484484
     485    $r['caller_get_posts'] = true;
     486
    485487    $get_posts = new WP_Query;
    486488    return $get_posts->query($r);
     
    748750
    749751    return $custom[$key];
     752}
     753
     754/**
     755 * is_sticky() - Check if post is sticky
     756 *
     757 * {@internal Missing Long Description}}
     758 *
     759 * @package WordPress
     760 * @subpackage Post
     761 * @since 2.7
     762 *
     763 * @param int $post_id A post ID
     764 * @return bool
     765 */
     766function is_sticky($post_id) {
     767    $stickies = get_option('sticky_posts');
     768
     769    if ( !is_array($stickies) )
     770        return false;
     771
     772    if ( in_array($post_id, $stickies) )
     773        return true;
     774
     775    return false;
    750776}
    751777
     
    846872
    847873    return $value;
     874}
     875
     876/**
     877 * Make a post sticky
     878 *
     879 * Makes a post stick to the top of the front page
     880 *
     881 * @package WordPress
     882 * @subpackage Post
     883 * @since 2.7
     884 *
     885 * @param int $post_id A post ID
     886 */
     887function stick_post($post_id) {
     888    $stickies = get_option('sticky_posts');
     889
     890    if ( !is_array($stickies) )
     891        $stickies = array($post_id);
     892
     893    if ( ! in_array($post_id, $stickies) )
     894        $stickies[] = $post_id;
     895
     896    update_option('sticky_posts', $stickies);
     897}
     898
     899/**
     900 * Unstick a post
     901 *
     902 * Unstick a post from the front page
     903 *
     904 * @package WordPress
     905 * @subpackage Post
     906 * @since 2.7
     907 *
     908 * @param int $post_id A post ID
     909 */
     910function unstick_post($post_id) {
     911    $stickies = get_option('sticky_posts');
     912
     913    if ( !is_array($stickies) )
     914        return;
     915
     916    if ( ! in_array($post_id, $stickies) )
     917        return;
     918
     919    $offset = array_search($post_id, $stickies);
     920    if ( false === $offset )
     921        return;
     922
     923    array_splice($stickies, $offset, 1);
     924   
     925    update_option('sticky_posts', $stickies);
    848926}
    849927
Note: See TracChangeset for help on using the changeset viewer.