简体   繁体   中英

I am trying to make the 3rd, 4th, 6th, 7th etc wordpress blog posts display in one news box. The pictures i have attached explains better

I am working with post count on my blog page and have achieved what is depicted in the picture below. I am trying to make the 3rd, 4th 6th 7th etc blog post fit (The ones i wrapped with the ) into one news box. I have been able to achieve that and I am doing fine with the css codes, i have removed their thumbnails, but as depicted in the below picture the 4th and 5th posts are the same(Notice the titles and meta datas are the same).

How do I make the 3th and 4th post display different posts, Am I to loop twice inside the doublebox class or how am i supposed to go about solving this problem?

Here's a picture depicting what I have now

在此处输入图片说明

Here's an image of what I want to acheive

在此处输入图片说明

Here's my loop below

if( $lastBlog->have_posts() ):

            $count = 0; //start counter

                while( $lastBlog->have_posts() ): $lastBlog->the_post(); ?>

            <?php $count++; ?>
                <?php if( $count % 4 != 0 && $count % 4 != 3  ):  ?>
                        <?php get_template_part('frontpage-template-parts/content','col6'); ?>

                <?php elseif( $count % 4 == 0 || $count % 4 == 3 ):  ?> 
                    <div class="col-md-6"><div class="news_box doublebox">                  
                        <?php get_template_part('frontpage-template-parts/content','singlebox'); ?>             
                        <?php get_template_part('frontpage-template-parts/content','singlebox'); ?>                     
                    </div></div>

                    <?php else :  ?>
                        <?php get_template_part('frontpage-template-parts/content','col6'); ?>  
                <?php endif; ?>             
    <?php 
        endwhile;

        endif;

This code below is spitting it out the post twice so it's going to show those results two times before moving on to the next post.

<?php get_template_part('frontpage-template-parts/content','singlebox'); ?>             
<?php get_template_part('frontpage-template-parts/content','singlebox'); ?>

Removing one of these lines will solve your issue, but you'll also need to make another adjustment to fix the surrounding divs. Something like this:

<?php elseif( $count % 4 == 3 ):  ?> 
  <div class="col-md-6">
    <div class="news_box doublebox">                  
      <?php get_template_part('frontpage-template-parts/content','singlebox'); ?>
<?php elseif( $count % 4 == 0 ):  ?>
      <?php get_template_part('frontpage-template-parts/content','singlebox'); ?>                     
    </div>
  </div>
<?php else : ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM