2016-04-12 30 views
0

Wordpress sitemde 3x'lik bir kılavuzda yayınlarım var. Bu, çıktıyı üreten koddur.Grid'de Özel Gönderi Düzeni

<div class="first-post"> 
      <?php if (have_posts()) : the_post(); ?> 

      <!-- calling first the_post(); will step the loop forward --> 

      <?php get_template_part('content','grid-firstpost'); ?> 
      <?php endif; ?> 
     </div> 


     <div class="other-posts"> 
      <?php $i = 1; ?> 
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>      
       <!-- the loop will be at the 2nd post here --> 
       <?php get_template_part('content','grid'); ?>           
       <?php if ($i%3 == 0) : ?> 
        <div class="clearfix"></div> 
       <?php endif; $i++; ?> 

       <?php if ($_SERVER["REQUEST_URI"] == '/'): ?> 
       <?php if ($i == 3): ?> 
       <?php if (have_posts()) : the_post(); ?> 
        <!-- calling the_post(); will step the loop forward --> 
        <?php get_template_part('content','grid-test'); ?> 
        <?php if ($i%3 == 0) : ?> 
        <div class="clearfix"></div> 
       <?php endif; $i++; ?> 
        <?php endif; ?> 
       <?php endif ?> 
       <?php endif ?> 

       <?php if ($i == 7): ?> 
        <div class="first-post"> 
         <!-- making post 7 fullwidth --> 
         <?php get_template_part('content','grid-firstpost'); ?> 
        </div> 
       <?php endif ?> 


      <?php endwhile; wp_reset_query(); endif; ?> 

     </div> 

Kılavuzdaki üçüncü nokta için özel bir div oluşturdum. Sorun şu ki, başlangıçta bu noktaya sahip olması gereken posta, özel div (<?php if ($i == 3): ?>) nedeniyle gizlenmiş.

+ Tam geniş sonrası +

İlk mesaj           İkinci Mesaj     Özel Div

Dördüncü sonrası  :

Yani çıkış böyledir 10 Beşinci Mesaj               Altıncı Mesaj

olması gerektiği Ne:

+ Tam geniş sonrası +

Sonraki İlk       İkinci Mesaj     Özel Div

Üçüncü Mesaj     Dördüncü Mesaj       Beşinci Mesaj


Bunu çözmek için nasıl bilmiyorum.

cevap

0

3 olması durumunda, $ i değişkenini iki kez artırıyor gibi görünüyorsunuz. Sadece while döngüsünün sonunda artırın, böylece döngü süresi boyunca sabit kalır.

<div class="other-posts"> 
    <?php $i = 1; ?> 
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>      

<!-- Style the grid post 3 with a custom div --> 

    <?php if ($i == 3): ?> 
     <?php get_template_part('content','grid-customdiv'); ?> 
    <?php endif; ?> 

    <?php if ($i%3 == 0) : ?> 
     <div class="clearfix"></div> 
    <?php endif; ?> 

    <?php get_template_part('content','grid'); ?> 


    <?php $i++; ?> 

    <?php endwhile; wp_reset_query(); endif; ?> 

</div> 
+0

Yalnızca siparişi buradan düzeltin, şimdi çalışmalı – larsAnders

+0

Bu işe yaramıyor. 3 post sonrası ızgara durağı. Kod şimdi güncellendi. – Musa

+0

Tamam, cevap düzenlenmiş. Bunu deneyin - bence ihtiyacınız olan tek şey – larsAnders