logo

$10
show just 4 sticky posts

I have a normal home page with no dynamic content, but a loop to shows sticky posts above the normal loop
<div id="slider">

<?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 &raquo;', 'news'); ?></a>

</div>
</div>

</div>

<?php endwhile; wp_reset_query(); ?>

</div>
It shows stickys but not just 4, I want the 4 most recent sticky posts to display

Rick Bible | 05/11/10 at 3:30pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    05/11/10
    4:04pm
    Oleg 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;

      ?>

  • avatar
    Last edited:
    05/11/10
    3:35pm
    Utkarsh Kukreti says:

    Use

    'numberposts' => 4

  • avatar
    Last edited:
    05/11/10
    3:38pm
    Erez S says:

    Replace showposts with posts_per_page or numberposts

    Previous versions of this answer: 05/11/10 at 3:38pm

This question has expired.





Current status of this question: Completed