繁体   English   中英

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM