0

Hello I want to display posts like this.

<div class="item">
  <div class="row">
    Post No 1.
    Post No 2.
  </div>
  <div class=row 2>
    Post No 3.
    Post No 4.
    Post No 5.
  <div>
</div>

Here is code what i am trying.

 <?php 
                    global $paged, $wp_query, $wp;
                    $arags = array(
                        'post_type' => 'post',
                        'posts_per_page' => 5,
                    );
                    $count = 1;
                    $itemClass = '';
                    $wp_query = new WP_Query($arags);
                    while ($wp_query->have_posts()) : $wp_query->the_post();
                    ?>
                    <?php 
                    if($count == 1) :
                        echo '<div class="item">';
                        echo '<div class="row">';
                    endif;

                    if($count == 1 || $count == 2) :
                        get_template_part( 'templates/mag/mag-loop-big' );
                    endif;


                    if($count == 1) :
                        echo '</div>';
                        echo '</div>';
                    endif;
                    ?>
                    <?php $count++; ?>                      
                    <?php endwhile; ?>
                    <?php wp_reset_postdata(); ?>
                    <?php wp_reset_query(); ?>

This Code display first post in Item and Div class. But second div shown out side of row and item div. Here is current result.

<div class="item">
<div class="row">
    Post No 1.
 </div>
</div>
 Post No 2.
 Post No 3.
Post No 4.

Any solution for this?? Thanks in advance.

3
  • show the result of your codes Commented Aug 26, 2017 at 6:53
  • Because you have closed div after first post if($count == 1) : echo '</div>'; echo '</div>'; endif; Commented Aug 26, 2017 at 6:58
  • Result added Question updated. Commented Aug 26, 2017 at 6:58

1 Answer 1

1

your conditions are not the right one for that result try this

if($count == 1) :
echo '<div class="item">';
echo '<div class="row">';
if($count == 1) :
get_template_part( 'templates/mag/mag-loop-big' );
endif;
if($count == 2) :
echo '</div>';
endif;
 if($count == 3) :
 echo '<div class="row2">';
 if($count == 5) :
 echo '</div>';
 echo '</div>';
 endif;
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.