Make WordPress Core

Changeset 8637


Ignore:
Timestamp:
08/13/2008 06:21:52 PM (18 years ago)
Author:
ryan
Message:

Add sticky_class() template tag. see #7457

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/classic/index.php

    r7869 r8637  
    77<?php the_date('','<h2>','</h2>'); ?>
    88
    9 <div class="post" id="post-<?php the_ID(); ?>">
     9<div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
    1010         <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    1111        <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_tags(__('Tags: '), ', ', ' &#8212; '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
  • trunk/wp-content/themes/default/index.php

    r6132 r8637  
    77                <?php while (have_posts()) : the_post(); ?>
    88
    9                         <div class="post" id="post-<?php the_ID(); ?>">
     9                        <div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
    1010                                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    1111                                <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
  • trunk/wp-includes/post-template.php

    r8600 r8637  
    159159        $post = &get_post( $id );
    160160        return ( !empty( $post->post_excerpt ) );
     161}
     162
     163/**
     164 * Echo "sticky" CSS class if a post is sticky
     165 *
     166 * {@internal Missing Long Description}}
     167 *
     168 * @package WordPress
     169 * @subpackage Post
     170 * @since 2.7
     171 *
     172 * @param int $post_id An optional post ID
     173 */
     174function sticky_class( $post_id = null ) {
     175        if ( !is_sticky($post_id) )
     176                return;
     177
     178        echo " sticky";
    161179}
    162180
  • trunk/wp-includes/post.php

    r8636 r8637  
    764764 * @return bool
    765765 */
    766 function is_sticky($post_id) {
     766function is_sticky($post_id = null) {
     767        global $id;
     768
     769        $post_id = absint($post_id);
     770
     771        if ( !$post_id )
     772                $post_id = absint($id);
     773
    767774        $stickies = get_option('sticky_posts');
    768775
    … …  
    775782        return false;
    776783}
     784
    777785
    778786/**
  • trunk/wp-includes/query.php

    r8600 r8637  
    15241524
    15251525                        // Fetch sticky posts that weren't in the query results
    1526                         $stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
    1527                         $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" );
    1528                         // TODO Make sure post is published or viewable by the current user
    1529                         foreach ( $stickies as $sticky_post ) {
    1530                                 if ( 'publish' != $sticky_post->post_status )
    1531                                         continue;
    1532                                 array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
    1533                                 $sticky_offset++;
     1526                        if ( !empty($sticky_posts) ) {
     1527                                $stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
     1528                                $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" );
     1529                                // TODO Make sure post is published or viewable by the current user
     1530                                foreach ( $stickies as $sticky_post ) {
     1531                                        if ( 'publish' != $sticky_post->post_status )
     1532                                                continue;
     1533                                                array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
     1534                                                $sticky_offset++;
     1535                                }
    15341536                        }
    15351537                }
Note: See TracChangeset for help on using the changeset viewer.