2016-11-04 53 views
0

我正在使用我的博客頁面上的帖子數量,並已實現了下圖中所示的內容。我正在嘗試將第三,第四,第六,第七等博客帖子合併到一個新聞框中。我已經能夠實現這一點,我做的很好的CSS代碼,我已經刪除了他們的縮略圖,但如下圖所示,第4和第5帖是相同的(注意標題和元數據是相同的)。我正在嘗試在一個新聞框中顯示第3,第4,第6,第7等wordpress博客帖子。我附上的圖片更好地解釋

我該如何讓第三和第四個帖子顯示不同的帖子,我是否會在雙層箱子內循環兩次,或者我該如何解決這個問題?

這裏有一張描繪了什麼我現在

enter image description here

這裏是什麼,我想acheive

enter image description here

這裏是我的下面循環的圖像

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; 

回答

-1

下面的代碼正在吐出兩次帖子,所以它會在展開下一篇文章之前展示兩次結果。

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

刪除這些行的人會解決你的問題,但你還需要再作調整,以解決周圍的div。這樣的事情:

<?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 : ?> 
+0

感謝您的迅速反應喬,它像一個魅力工作。 –

相關問題