• Hey I am attempting to customize my wordpress post loop to create different post style for a certain set of post.

    For example the first three post would be styled in it’s own way, the next four post will be style in it’s own way and etc.

    In addition to that I want to add <div> breaks after a certain amount of post. See image below for what I am trying to accomplish.

    http://cdn.ratedrnb.com/2016/04/photo.png

    Now this code below is what I use to style the post differently.

    <?php if (have_posts()) :
        $count = 0;
    
        // What page are we on?
        $paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
        // How many pages of posts do we have to display?
        //$max = $wp_query->max_num_pages;
    
        while (have_posts()) : the_post();      
    
        $count++;
    
        if ($count  == 1 && $paged == 1) : ?> 
    
         <!--first post -->
    
         **html/style of the first post**
    
         <!--next four post -->
    
         <?php elseif ($count  > 1 && $count  <5 && $paged == 1) : ?>
    
         **html/style of next four post**
    
         <!-- 4th post and break div -->
    
        <?php elseif ($count  == 5 && $paged == 1) : ?> 
    
        **html/style of fourth post**
    
        <div>This is the div break</div>
    
        <!--next five post -->
    
         <?php elseif ($count >5 && $count < 11 && $paged == 1) : ?> 
    
        **html/style of next six post**
    
        <!--sixth post and div break-->
    
         <?php elseif ($count == 11 && $paged == 1) : ?>
    
        **html/style of 6th post**
    
         <div>This is the div break</div>
    
         <!--last eight post-->
    
        <?php elseif ($count  > 12 && $count  < 21 && || $paged == 1) : ?>
    
        **html/style of last eight post**
    
          <?php endif;
        endwhile;
        endif; ?>

    Now this code is also designed so that when I go to the next page the rest of the pages takes the style of the last eight post.

    Can anyone explain to me how to change this line below to show the first 3 post instead of just one.

    <?php if (have_posts()) :
        $count = 0;
    
        // What page are we on?
        $paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
        // How many pages of posts do we have to display?
        //$max = $wp_query->max_num_pages;
    
        while (have_posts()) : the_post();      
    
        $count++;
    
        if ($count  == 1 && $paged == 1) : ?>

    Also can anyone explain to me why the person I hired to do this had to separate the loop like below.

    <!--next four post -->
    
         <?php elseif ($count  > 1 && $count  <5 && $paged == 1) : ?>
    
         **html/style of next four post**
    
         <!-- 4th post and break div -->
    
        <?php elseif ($count  == 5 && $paged == 1) : ?> 
    
        **html/style of fourth post**
    
        <div>This is the div break</div>

The topic ‘How to change wordpress loop count?’ is closed to new replies.