2013-10-01 88 views
0

我需要在每個Wordpress之間的div中添加一些靜態內容。以下是我迄今爲止...在while循環中添加靜態內容inbetween Wordpress帖子

query_posts('cat=technology');?> 
<?php 
    $i=1; 
    if (have_posts()) : while (have_posts()) : the_post(); 
    $feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
    echo $i++; //Echoing $i to see if incrementing works ok 
?> 
<div class="masonryImage" style="width: 300px; height:250px;"> 
<img width="300" height="250" src= "<? echo $feat_image ?>" alt="<? echo the_title(); ?>" /> 
</div> 
<?php endwhile; endif; ?> 

所以在<div class="masonryImage">我需要奇數指標加載WordPress的職位,而偶數索引加載重複靜態內容。這可以解釋更多...

<div class="masonryImage"> //Index 1 
WORDPRESS POST 
</div> 
<div class="masonryImage"> //Index 2 
STATIC CONTENT 
</div> 
<div class="masonryImage"> //Index 3 
WORDPRESS POST 
</div> 

任何方式來做到這一點?提前致謝!

回答

3

試試這個:

query_posts('cat=technology');?> 
<?php 
$i=1; 
if (have_posts()) : while (have_posts()) : the_post(); 
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
echo $i++; //Echoing $i to see if incrementing works ok 
?> 
<div class="masonryImage" style="width: 300px; height:250px;"> 
<img width="300" height="250" src= "<? echo $feat_image ?>" alt="<? echo the_title(); ?>" /> 
</div> 
<?php 
if ($i%2 == 0){ ?> // this block here will be executed every second time 
    <div class="masonryImage"> //Index 2 
     STATIC CONTENT 
    </div> 
<?php } 
?> 
<?php endwhile; endif; ?> 
+0

輝煌,工作一種享受,對於謝謝! :) –