2014-10-07 90 views
0

我正在將WP博客集成到Magento中。我有一個無限循環的自定義博客帖子頁面。我有無限數量的行,每行有3個帖子。我想用Magento產品目錄中的精選產品替換5th和9的發佈位置。如何在無限循環中定位第5和第9個元素?

這是我想實現的樣機。目前它顯示無限循環的帖子。

Mockup

這裏是基本:任何人都可以提出什麼是更好的做法是目標5和第9元,並建議如何改善循環。

另外,如果有人知道我可以在那個地方展示Magento的產品,那就太棒了。

<div class="loop"> 
    <?php while (have_posts()) : the_post(); ?> 
     <?php get_template_part('content', $post->post_type); ?> 
    <?php endwhile; ?> 

    <?php skeleton_content_nav('nav-below'); ?> 
</div><!-- .loop --> 

提前致謝!

+1

退房[此帖](http://wordpress.stackexchange.com/q/158133/31545),並且鏈接到 – 2014-10-07 10:47:42

回答

0

做這樣

<div class="loop"> 
<?php 
    $i=1; 
    while (have_posts()) : the_post(); 

     if($i==5){ 

      // ITEM 1 : Highlight featured product from the Magento catalogue item. 
       echo '<div> Your Custom 5 th Element</div>'; 
      // Or 
      //if you have created function for it then call it here 
      featureProduct($i); 



     }else if($i==9){ 

      // ITEM 2 : Highlight featured product from the Magento catalogue item. 
           echo '<div> Your Custom 9 th Element</div>'; 
      // Or 
      //if you have created function for it then call it here 
      featureProduct($i); 

     }else{ 
      // Post 
      get_template_part('content', $post->post_type); 
     } 

     // Reset $i variable 
     if($i==9){ $i=0; } 

     $i++; 
    endwhile; 

    <?php skeleton_content_nav('nav-below'); ?> 
</div><!-- .loop --> 
+0

我怎麼能分開循環後檢查是否($ i = 5){做這個} else if($ i = 9){做這個}?它會起作用嗎? – ummahusla 2014-10-07 10:03:53

+0

@Tibbers是的,如果你想讓y0在每個循環5和9上獲得不同的項目。 – 2014-10-07 10:04:59

+0

你可以請更新循環爲不同的項目?謝謝 – ummahusla 2014-10-07 10:06:17

相關問題