2013-03-19 97 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