在 While 循环中的 Wordpress 帖子之间添加静态内容


Add Static content inbetween Wordpress posts in While loop

我需要在每个Wordpress之间的div中添加一些静态内容。这是我到目前为止所拥有的...

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>

有什么办法可以做到这一点吗?提前感谢!

试试这个:

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; ?>