gpt4 book ai didi

switch-statement - ExpressionEngine 表中的交替行颜色

转载 作者:行者123 更新时间:2023-12-04 08:31:32 25 4
gpt4 key购买 nike

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

<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 中做类似的事情吗?

谢谢!

最佳答案

您正在寻找开关标签。

{switch="奇|偶"}

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

关于switch-statement - ExpressionEngine 表中的交替行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15509702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com