I am working on an Expression Engine site and I am trying to get the content from two different channels to display in the same section based on a condition.
The home page has a slider that links to a variety of content. I created a channel for this with four fields. The article section has independent content but on occasion this needs to be highlighted in the slider on the home page.
To meet this need I added a "display in slider" field with a NO/YES option followed by fields that hold content similar to the slider content but with unique names.
Here is the challenge: how do I write the conditional to display only those entries where the "display in slider" field is set to YES. The following code has one flaw: it still displays part of the content from the entries where the "display in slider" is set to NO because it meets the conditions of the if:else options.
Here is the code:
<div id="slider">
{exp:channel:entries channel="slider|garden_advice" disable="categories|category_fields|member_data|pagination"}
{if display_in_slider == "YES"}
<div class="slider-content">
<div class="slider-image">
<img src="{slider_photo_ga}" alt="{title}" >
</div>
<h3>{title}</h3>
<span class="sub-title">{sub_title_ga}</span>
<p>{slider_text_ga}</p>
<div class="link-box">
<a href="{site_url}garden-advice/article/{url_title}">{link_text_ga}</a>
</div>
</div><!-- end .slider-content -->
{if:else}
<div class="slider-content">
<div class="slider-image">
<img src="{slider_photo}" alt="{title}" >
</div>
<h3>{title}</h3>
<span class="sub-title">{sub_title}</span>
<p>{slider_text}</p>
{if entry_id != 5014}
<div class="link-box">
{link_text}
</div>
{if:else}
{link_text}
{/if}
</div><!-- end .slider-content -->
{/if}
{/exp:channel:entries}
</div><!-- end .slider -->
My question is: how can I modify the conditional so that only the garden_advice channel is considered in the first if statement and only the slider channel is considered in the second one?
Thanks!
Just include the channel_short_name
in the conditional:
{if channel_short_name == "garden_advice" && display_in_slider == "YES"}
Etc.
You could also try adding search:display_in_slider="YES"
to your Channel Entries tag ... I'm not sure how that will work with two channels in the channel
parameter (EE may see that that field is not in the "slider" channel and just ignore the parameter, or it may omit all of that channel's entries entirely), but it's worth a shot.