2013-09-26 57 views
0

我想查詢要顯示在WordPress網站主頁上的帖子圖片。將div加到循環中的每一行

我想最後的結果看起來像這樣 - enter image description here

我可以得到跨度來顯示正確,但我不知道怎麼引導的「行」類添加到每一行。

這裏是我迄今爲止 -

任何幫助表示讚賞。

謝謝!

$args = array('post_type' => 'video', 'posts_per_page' => 10,); 

$the_query = new WP_Query($args); 

echo '<section id="our-work">'; 

if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

    $counter += 1; 

    if($counter == 4 || $counter == 5 || $counter == 9 || $counter == 10) : 

    echo '<div class="span6">'; 
    the_post_thumbnail();; 
    echo '</div>'; 

    else: 

    echo '<div class="span4">'; 
    the_post_thumbnail(); 
    echo '</div>'; 

    endif; 


endwhile; endif; 

echo '</section>'; 
+0

不是沒有,但我真的希望PHP沒有維護的伎倆VB -esque語法。可讀性 - ; –

回答

4

確實有一個更優雅的方式來做到這一點......但這應該工作。

$args = array('post_type' => 'video', 'posts_per_page' => 10,); 

$the_query = new WP_Query($args); 

echo '<section id="our-work">'; 

if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 
    $counter += 1; 

    if ($counter == 1 || $counter == 4 || $counter == 6 || $counter == 9) { 
     echo '<div class="row">'; 
    } 

    if($counter == 4 || $counter == 5 || $counter == 9 || $counter == 10) : 

    echo '<div class="span6">'; 
    the_post_thumbnail(); 
    echo '</div>'; 

    else: 

    echo '<div class="span4">'; 
    the_post_thumbnail(); 
    echo '</div>'; 

    endif; 

    if ($counter == 3 || $counter == 5 || $counter == 8 || $counter == 10) { 
     echo '</div>'; 
    } 

endwhile; endif; 

echo '</section>'; 
+0

謝謝KHMKShore! –

2

毫無疑問,它可以有不同的書面 - 或爲此事更好,但這應該做的:)

if($counter % 3 == 0) { 
    $current_class = "span6"; 
} else { 
    $current_class = "span4"; 
} 

// your stuff here 
echo '<div class="'.$current_class.'">'; 
相關問題