Add sticky_class() template tag. see #7457

git-svn-id: http://svn.automattic.com/wordpress/trunk@8637 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-13 18:21:52 +00:00
parent b76abe33b4
commit 15440186be
5 changed files with 40 additions and 12 deletions

View File

@ -6,7 +6,7 @@ get_header();
<?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>
<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(); ?>
<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>
<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 ) );
}
/**
* 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 = '') {
$defaults = array(
'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
* @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');
if ( !is_array($stickies) )
@ -775,6 +782,7 @@ function is_sticky($post_id) {
return false;
}
/**
* sanitize_post() - Sanitize every post field
*

View File

@ -1523,14 +1523,16 @@ class WP_Query {
}
// Fetch sticky posts that weren't in the query results
$stickies__in = implode(',', array_map( 'absint', $sticky_posts ));
$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
foreach ( $stickies as $sticky_post ) {
if ( 'publish' != $sticky_post->post_status )
continue;
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
$sticky_offset++;
if ( !empty($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)" );
// TODO Make sure post is published or viewable by the current user
foreach ( $stickies as $sticky_post ) {
if ( 'publish' != $sticky_post->post_status )
continue;
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
$sticky_offset++;
}
}
}
@ -1759,4 +1761,4 @@ function setup_postdata($post) {
return true;
}
?>
?>