Add sticky_class() template tag. see #7457

git-svn-id: https://develop.svn.wordpress.org/trunk@8637 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-08-13 18:21:52 +00:00
parent c53da5a523
commit 2b8caf9a1f
5 changed files with 40 additions and 12 deletions

View File

@ -6,7 +6,7 @@ get_header();
<?php the_date('','<h2>','</h2>'); ?> <?php the_date('','<h2>','</h2>'); ?>
<div class="post" id="post-<?php the_ID(); ?>"> <div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<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> <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>

View File

@ -6,7 +6,7 @@
<?php while (have_posts()) : the_post(); ?> <?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>"> <div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

View File

@ -160,6 +160,24 @@ function has_excerpt( $id = 0 ) {
return ( !empty( $post->post_excerpt ) ); return ( !empty( $post->post_excerpt ) );
} }
/**
* Echo "sticky" CSS class if a post is sticky
*
* {@internal Missing Long Description}}
*
* @package WordPress
* @subpackage Post
* @since 2.7
*
* @param int $post_id An optional post ID
*/
function sticky_class( $post_id = null ) {
if ( !is_sticky($post_id) )
return;
echo " sticky";
}
function wp_link_pages($args = '') { function wp_link_pages($args = '') {
$defaults = array( $defaults = array(
'before' => '<p>' . __('Pages:'), 'after' => '</p>', 'before' => '<p>' . __('Pages:'), 'after' => '</p>',

View File

@ -763,7 +763,14 @@ function get_post_custom_values( $key = '', $post_id = 0 ) {
* @param int $post_id A post ID * @param int $post_id A post ID
* @return bool * @return bool
*/ */
function is_sticky($post_id) { function is_sticky($post_id = null) {
global $id;
$post_id = absint($post_id);
if ( !$post_id )
$post_id = absint($id);
$stickies = get_option('sticky_posts'); $stickies = get_option('sticky_posts');
if ( !is_array($stickies) ) if ( !is_array($stickies) )
@ -775,6 +782,7 @@ function is_sticky($post_id) {
return false; return false;
} }
/** /**
* sanitize_post() - Sanitize every post field * sanitize_post() - Sanitize every post field
* *

View File

@ -1523,6 +1523,7 @@ class WP_Query {
} }
// Fetch sticky posts that weren't in the query results // Fetch sticky posts that weren't in the query results
if ( !empty($sticky_posts) ) {
$stickies__in = implode(',', array_map( 'absint', $sticky_posts )); $stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
$stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" ); $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" );
// TODO Make sure post is published or viewable by the current user // TODO Make sure post is published or viewable by the current user
@ -1533,6 +1534,7 @@ class WP_Query {
$sticky_offset++; $sticky_offset++;
} }
} }
}
$this->posts = apply_filters('the_posts', $this->posts); $this->posts = apply_filters('the_posts', $this->posts);