2014-02-15 28 views
-1

有人可以將此代碼轉換爲純php。在多個條目後添加內容,請繼續輸入

{assign var="counter" value="0"} 
{$counter=0} 
{foreach from=$entries item=entry} 
    {math equation="x + 1" x=$counter assign="counter"} 

    <div class="entry">...</div> 

    {if $counter==6} 

    <div class="content">...</div> 

    {/if} 
{/foreach} 

非常感謝,對不起我的PHP文盲。

編輯: $計數器記錄列出了多少條目(在本例中是來自數據庫的圖像),並且在某個數字後顯示一些外部內容(例如:廣告),然後條目繼續從它們的位置的左邊。

回答

0
$counter = 1; 
foreach ($entries as $entry) { 
    echo '<div class="entry">...</div>'; 

    // If the counter value is divisible by 6, then output the extra content. 
    // Increment the counter afterwards 
    if ($counter++ % 6 == 0) { 
     echo '<div class="content">...</div>'; 
    } 
} 

這並不是真的很清楚你想達到什麼,所以有我的解釋。

+0

$計數器記錄列出了多少條目(本例中是來自數據庫的圖像),並且在某個數字後顯示一些外部內容(例如:廣告),然後條目繼續從他們離開的位置列出。 – user3314293

+0

如果您希望在每6個元素之後顯示外部內容,那就不同了。我會相應地編輯代碼。 –