$10
show just 4 sticky posts
<div id="slider">It shows stickys but not just 4, I want the 4 most recent sticky posts to display
<?php query_posts(array('post__in'=>get_option('sticky_posts'), 'showposts' => 4 )); ?>
<?php while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="<?php hybrid_entry_class( 'feature' ); ?>">
<?php get_the_image( array( 'custom_key' => array( 'feature' ), 'default_size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
<div class="text-box">
<h2 class="slider-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?>
</a></h2>
<div class="entry-summary entry">
<!-- <?php the_excerpt(); ?> -->
<a class="more-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php _e('Full Story »', 'news'); ?></a>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
Rick Bible | 05/11/10 at 3:30pm
| Edit
(3) Possible Answers Submitted...
-
Last edited:
05/11/10
4:04pmOleg Butuzov says:<?php
query_posts(
array('post__in'=>get_option('sticky_posts'),
'showposts' => 4 ,
'order' => 'desc',
'orderby' =>'date')
);
?>Previous versions of this answer: 05/11/10 at 3:36pm
- 05/11/10 3:40pm
Oleg Butuzov says:'order' => 'desc' ,
'orderby' =>'date'
is a order fields , you can specify yours...
right now it will take 4 most new posts... - 05/11/10 3:45pm
Rick Bible says:none of these work, they work no differently than what I already have... see, if my client has 10 stickys checked, I only want the four most recent. My code, and this code, as well as variations below are still showing all the stickys checked.
- 05/11/10 3:50pm
Oleg Butuzov says:
add_filter('option_posts_per_page', 'total_posts_in_category');
query_posts(
array('post__in'=>get_option('sticky_posts'),
'showposts' => 4 ,
'order' => 'asc',
'orderby' =>'date')
);
remove_filter('option_posts_per_page', 'total_posts_in_category');
function total_posts_in_category(){
return 4;
}
- 05/11/10 3:55pm
Oleg Butuzov says:setting 4 for everithing!
add_filter('option_posts_per_page', 'totala_posts_in_category');
query_posts(
array(
'post__in'=>get_option('sticky_posts'),
'showposts' => 4 ,
'order' => 'asc',
'orderby' =>'date',
'posts_per_page'=>4
)
);
remove_filter('option_posts_per_page', 'totala_posts_in_category');
function totala_posts_in_category(){
return 4;
}
- 05/11/10 3:57pm
Rick Bible says:No luck, would it be easier to do a tag, say "featured", and show 4 most recent featured tags?
- 05/11/10 4:00pm
Oleg Butuzov says:this is finality. and fatality of your problem
<?php
$sticky = get_option('sticky_posts');
rsort( $sticky );
$sticky = array_slice( $sticky, 0, 3);
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
if (have_posts()) :
while (have_posts()) : the_post();
// code here
endwhile;
endif;
?>
- 05/11/10 3:40pm
-

Last edited:
05/11/10
3:35pm -

Last edited:
05/11/10
3:38pmErez S says:Replace showposts with posts_per_page or numberposts
Previous versions of this answer: 05/11/10 at 3:38pm
- 05/11/10 3:54pm
Erez S says:Here is another solution:
$sticky=get_option('sticky_posts') ;
query_posts('p=' . $sticky[0].','.$sticky[1].','.$sticky[2].','.$sticky[3]);
//LOOP
Should work,if not,try to use seperate query_posts for each sticky,and read this for more information:
http://codex.wordpress.org/Function_Reference/query_posts#Sticky_Post_Parameters
- 05/11/10 3:54pm
This question has expired.
Current status of this question: Completed




