簡體   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