2

我有一些代码可以创建一个表,该表根据条目的行值交替行颜色。

<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>

问题是当我删除一个条目时,我最终会连续有两个奇数或两个偶数,留下两个并排的颜色相同的行。

虽然 switch 函数很方便,但它引用了数据库中的行数。我不相信我可以应用它来引用 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 中做类似的事情吗?

谢谢!

4

2 回答 2

5

您正在寻找 switch 标签。

{switch="奇数|偶数"}

但看起来你已经知道了。看起来您需要将变量 team-not-with-us 设置为 != 'y'。因为您在返回结果后进行验证,所以您将以多个奇数行或偶数行彼此相邻结束。避免这种情况的简单方法是使用 channel:entries 搜索参数。示例:search:team-not-with-us="not y"

<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>
于 2013-03-20T12:03:46.800 回答
1

您可能想尝试在https://expressionengine.stackexchange.com/上询问 EE 窥视{count} 标签应该可以工作。这只是计算(在您的情况下)在团队频道中的每个条目,并且在您的“团队不与我们”字段组中不是 Y,我假设它是一个开关或一个选择框或其他东西。

你输出的代码是什么样的?

于 2013-03-19T21:21:18.127 回答