1

I would like to have my main blogroll show 10 posts per page, but the first post of each page to be setup on a different div above the rest and have a featured image.

This is what I sued for the first post of the page:

// WP_Query arguments
$args = array (
    'pagination'             => true,
    'paged'                  => $paged,
    'posts_per_page'         => '10',
    'ignore_sticky_posts'    => true,
    'order'                  => 'DESC',
    'orderby'                => 'date',
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
        $query->the_post();
                the_title();
        the_content();
    } 
?>

and this was for the second:

<?php

// WP_Query arguments
$args = array (
    'pagination'             => true,
    'paged'                  => $paged,
    'posts_per_page'         => '9',
    'offset'                 => '1',
    'ignore_sticky_posts'    => true,
    'order'                  => 'DESC',
    'orderby'                => 'date',
);

// The Query
$query1 = new WP_Query( $args );

// The Loop
if ( $query1->have_posts() ) {
    while ( $query1->have_posts() ) {
        $query1->the_post();
        the_title();
        the_content();
    }
}

// Restore original Post Data
wp_reset_postdata();

?>

The first post changes when I page but the other 9 posts dont ever change even though they are getting the same paged arg as the first one.

Also I am up for any alternative ways you might have to achieve this. I saw a post that talked about altering the first post with a variable to mark the first time the loop ran but that doesnt help me because the first post needs to be out of the normal loop and in its own section.

Thank you ahead of time for any assistance you can give!

5

Creating 2 queries for your scope is absolutely an not need work...

Use only one query and use the $wp_query->current_post property to change the output of first post..

  $args = array (
    'pagination'             => true,
    'paged'                  => $paged,
    'posts_per_page'         => '10',
    'ignore_sticky_posts'    => true,
    'order'                  => 'DESC',
    'orderby'                => 'date',
  );

  // The Query
  $query = new WP_Query( $args );

  // The Loop
  if ( $query->have_posts() ) {

     $query->the_post();

     if ( $query->current_post == 0 ) {  // first post

       echo '<div class="first-post">';
       the_title();
       the_content();
       echo '</div>';

     } else {

        echo '<div class="second-to-ninth-post">';
        the_title();
        the_content();
        echo '</div>';

     }

     wp_reset_postdata();

  } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.