3

In ExpressioneEngine, I'm creating a list with conditionals that is returning some strange behavior. The code below is part of a bigger set:

<li><h4>DERMATOLOGY</h4>
  <ul>
    {exp:channel:entries channel="specialist" dynamic="no" orderby="sp_order" sort="asc"}
      {if sp_specialty == "sp_dermatology"}
        <li>
          <a href="{title_permalink='meet'}"><img src="{sp_headshot}" /></a>
          <a href="{title_permalink='meet'}"><p>{title}</p></a>
        </li>                           
      {/if}
    {/exp:channel:entries}
  </ul>
</li>
<li><h4>EMERGENCY AND CRITICAL CARE</h4>
  <ul>
    {exp:channel:entries channel="specialist" dynamic="no" orderby="sp_order" sort="asc"}
      {if sp_specialty == "sp_emergency"}
        <li class="{switch='one|two'}">
          <a href="{title_permalink='meet'}"><img src="{sp_headshot}" /></a>
          <a href="{title_permalink='meet'}"><p>{title}</p></a>
        </li>                           
      {/if}
    {/exp:channel:entries}
  </ul>
</li>

What happens, in the case of EMERGENCY AND CRITICAL CARE, is that with the 5 entries I have under that, the classes are returned like this: two, one, one, one, two. Any suggestions on getting the behavior I need?

4

1 に答える 1

6

私はあなたが何を意味するか分かります。switch 変数は、エントリ ループによって返されたすべてのエントリにそのロジックを適用します。これが、レンダリングされたページに奇数番号が表示される理由です。これは、条件を適用するループによって返されたエントリにそれらを適用しているためです。あなたのグループ化。検索パラメーターを使用して、その一部を実行し、各ループ内で探しているエントリのみを返すことができます。このような:

<li><h4>DERMATOLOGY</h4>
    <ul>
    {exp:channel:entries channel="specialist" search:sp_specialty="=sp_dermatology"  dynamic="no" orderby="sp_order" sort="asc"}
    <li>
      <a href="{title_permalink='meet'}"><img src="{sp_headshot}" /></a>
      <a href="{title_permalink='meet'}"><p>{title}</p></a>
    </li>                           
{/exp:channel:entries}
</ul>
</li>
<li><h4>EMERGENCY AND CRITICAL CARE</h4>
<ul>
{exp:channel:entries channel="specialist" search:sp_specialty="=sp_emergency" dynamic="no" orderby="sp_order" sort="asc"}
    <li class="{switch='one|two'}">
      <a href="{title_permalink='meet'}"><img src="{sp_headshot}" /></a>
      <a href="{title_permalink='meet'}"><p>{title}</p></a>
    </li>                           
{/exp:channel:entries}
</ul>
</li>

このようにして、各ループは探している一致するアイテムのみを返し、条件の必要性を排除し、switch パラメータが必要に応じて動作できるようにします - ループから返されたすべてのエントリに交互に適用されます。

于 2012-10-25T14:45:47.600 に答える