• Resolved f1ss1on

    (@f1ss1on)


    I am trying to get posts_per_page to work, and it is not limiting my query for 2 sticky posts to be listed. Any ideas on what is wrong?

    <div id="center">
            <ul class="feat-post">';
            query_posts('posts_per_page= 2');
              if (have_posts()) {
                while (have_posts()) : the_post();
                  if ( is_sticky() ) :
                    echo '<li><div class="featImage">';
                    the_post_thumbnail("featImage");
                    echo '</div><h1><a href="';
                    the_permalink();
                    echo '">';
                    the_title();
                    echo '</a></h1></li>';
                  endif;
                endwhile;
              }
              wp_reset_query();
        echo '</ul></div>;

    Any ideas on how to fix this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter f1ss1on

    (@f1ss1on)

    I figured it out.

    instead of using posts_per_page, I used the following,

    /* Get all Sticky Posts */
    $sticky = get_option( 'sticky_posts' );
    
    /* Sort Sticky Posts, newest at the top */
    rsort( $sticky );
    
    /* Get top 5 Sticky Posts */
    $sticky = array_slice( $sticky, 0, 5 );
    
    /* Query Sticky Posts */
    $query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );

    now my code looks like this and works flawlessly

    <div id="center">
            <ul class="feat-post">';
            /* Get all sticky posts */
            $sticky = get_option( 'sticky_posts' );
    
            /* Sort the stickies with the newest ones at the top */
            rsort( $sticky );
    
            /* Get the 5 newest stickies (change 5 for a different number) */
            $sticky = array_slice( $sticky, 0, 2 );
    
            /* Query sticky posts */
            query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
              if (have_posts()) {
                while (have_posts()) : the_post();
                  if ( is_sticky() ) :
                    echo '<li><div class="featImage">';
                    the_post_thumbnail("featImage");
                    echo '</div><h1><a href="';
                    the_permalink();
                    echo '">';
                    the_title();
                    echo '</a></h1></li>';
                  endif;
                endwhile;
              }
              wp_reset_query();
        echo '</ul></div>
    Thread Starter f1ss1on

    (@f1ss1on)

    Solved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘posts_per_page Not working’ is closed to new replies.