2013-03-19 96 views
2

我有一些代碼根據條目的行值創建一個交替行顏色的表。ExpressionEngine表中的交替行顏色

<table class="authorList" cellspacing="0"> 
{exp:channel:entries channel="team" disable="categories|member_data|pagination" orderby="team-last-name" sort="asc"} 
{if team-not-with-us != 'y'} 
    <tr class="{switch="odd|even"} authorInfo"> 

     <th class="authorName"> 
     {if team-bio != ''}<a href="{site_url}about/the-team/{url_title}">{/if} 
      {title} 
     {if team-bio != ''}</a>{/if} 
     </th> 
     <td class="position">{team-position}</td> 

    </tr> 
{/if} 
{/exp:channel:entries} 
</table> 

問題是,當我刪除的條目,我結束了連續有兩個奇數或兩個偶數,並排留下我有兩個相同顏色的行側。

雖然開關功能很方便,但它引用了數據庫中的行數。我不相信我可以用它來引用if語句中的實際行數來解決我的問題。 (糾正我,如果我錯了。)

我知道如何使用PHP這樣的變化:

<?php $oddevenrow = 0; ?> 
{if team-not-with-us != 'y'} 
    <?php $oddevenrow++; ?> 
    <?php ($oddeven = ($oddevenrow % 2 ? 'odd' : 'even')); ?> 
    <tr class="<?php echo $oddeven; ?> authorInfo"> 

但我不能在EE打開PHP安裝。

在EE中我能做些類似的事嗎?

謝謝!

回答

5

您正在尋找開關標籤。

{開關= 「奇|甚至」}

但它看起來像你已經知道了。看起來你需要變量team-not-with-us來!='y'。因爲你在結果返回後做了驗證,所以會以多個奇數行或偶數行結尾。避免這種情況的簡單方法是使用channel:entries search param。例如:搜索:team-not-with-us =「noty」

<table class="authorList" cellspacing="0"> 
{exp:channel:entries 
    channel="team" 
    disable="categories|member_data|pagination" 
    orderby="team-last-name" 
    sort="asc" 
    search:team-not-with-us="not y" 
} 
    <tr class="{switch="odd|even"} authorInfo"> 

     <th class="authorName"> 
     {if team-bio != ''}<a href="{site_url}about/the-team/{url_title}">{/if} 
      {title} 
     {if team-bio != ''}</a>{/if} 
     </th> 
     <td class="position">{team-position}</td> 

    </tr> 
{/exp:channel:entries} 
</table> 
+0

謝謝。我發誓我昨天晚上在看用戶指南(http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html)和「想法」我讀了這一切,但完全錯過了搜索參數。 – Yazmin 2013-03-20 17:12:25

1

您可能需要嘗試詢問EE偷看https://expressionengine.stackexchange.com/ {count}標籤應該起作用。這只是統計每個條目(在你的情況下)在團隊頻道中,而不是在你的「團隊不在我們」的現場組中,而我認爲這是一個開關或選擇框或其他東西。

你輸出的代碼是什麼樣的?

+0

謝謝。我不知道具體的ee交換。我會確保在那裏發佈我的問題。 – Yazmin 2013-03-20 17:47:30