Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:34:06+00:00 2026-06-13T15:34:06+00:00

In ExpressioneEngine, I’m creating a list with conditionals that is returning some strange behavior.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:34:08+00:00Added an answer on June 13, 2026 at 3:34 pm

    I see what you mean. The switch variable applies its logic to all entries returned by the entries loop – which is why you’re seeing odd numbering in your rendered page – because it’s applying them to entries returned by the loop that you are then applying conditionals to in order to do your grouping. You could use the search param to do some of that for you, returning only the entries you’re looking for within each loop. Like this:

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

    This way each loop returns ONLY the matching items you’re looking for, eliminating the need for the conditional and allowing the switch param to operate as it wants to – applying itself in alternating fashion to every returned entry from the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am querying my database using this code (showing part of code): In back
I have an ExpressionEngine template that is some global CSS styling. I have some
I have a simple list of images that is being controlled via a CMS
ExpressionEngine template code: <div class=container_16> <div class=grid_16> {if {segment_1} == home} {embed=include/title title=welcome} {if:elseif
We use the ExpressionEngine CMS (php) to create websites. For each site, we set
I am using ExpressionEngine 2.2.1 and am trying to create a conditional that will
Is this possible to do the following in ExpressionEngine: (code taken from here )
I am curious if there is a standard or open-source application that allows a
ExpressionEngine version is 1.6.8 and NOT upgradeable. I would like to set a session
I'm working with a CMS (ExpressionEngine) that wraps paragraph tags around images. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.