2014-09-25 63 views
0

我試圖將圖像添加到每三個帖子的博客提要中。我正在使用Fishpig的Magento wordpress集成擴展。在Wordpress/Magento中每3個帖子中添加一個圖片PHP循環

這是代碼我有工作:

<?php $posts = $this->getPosts() ?> 
<?php if (count($posts) > 0): ?> 
<div class="post-list"> 
    <ul id="post-list"> 
     <?php foreach($posts as $post): ?> 
      <li class="item<?php if ($post->isSticky()): ?> featured is-sticky<?php endif; ?> <?php echo $post->getPostFormat() ?>"> 
       <?php echo $this->getPostRenderer($post)->toHtml() ?> 
      </li> 
     <?php endforeach; ?> 

       </ul> 
    <script type="text/javascript">decorateList($('post-list'));</script> 
    <?php echo $this->getPagerHtml() ?> 
</div> 
<?php endif; ?> 

任何幫助將大規模讚賞。 謝謝

回答

0

它很簡單。

只需使用下面的代碼:

<?php $posts = $this->getPosts() ?> 
<?php if (count($posts) > 0): ?> 
    <div class="post-list"> 
     <ul id="post-list"> 
      <?php $count=0; foreach($posts as $post): ?> 
       <li class="item<?php if ($post->isSticky()): ?> featured is-sticky<?php endif; ?> <?php echo $post->getPostFormat() ?>"> 
        <?php $count++;if($count%3==0){?> 
         <img src="<?php echo {you image url}?>" /> 
        <?php }?> 
        <?php echo $this->getPostRenderer($post)->toHtml() ?> 
       </li> 
      <?php endforeach; ?> 

     </ul> 
    <script type="text/javascript">decorateList($('post-list'));</script> 
    <?php echo $this->getPagerHtml() ?> 
    </div> 
<?php endif; ?> 
相關問題