Hello,
I am hoping someone can help me with this. I feel like I should be able to figure this out, but I’m scratching my head…
For a multi-entry page I want to highlight the most recent entry where a toggle field is used to identify the entry as “featured”.
Basically, I am hoping the client does not have to turn off a previous Featured Entry’s toggle when they set a new featured entry, if that is possible.
A sample of my current code in an embed:
/{exp:channel:entries channel="newsEntry" dynamic="no" orderby="entry_date" limit="1"}
{if featuredNewsItem}
<div class="newsFeatureWrap">
<div class="newsFeatureImage" [removed]></div>
<div class="newsFeatureLeadIn">
<h2>FEATURED NEWS</h2>
<h3 class="title">{title}</h3>
{newsBodyText:limit characters="150"} <a href="http://news/{url_title}" title="Click to read the full article.">(read more)</a>
<a href="http://news/{url_title}" title="Click to read more about {title}." class="btn btn-white">Read More »</a>
</div>
</div>
{/if}
{/exp:channel:entries}
The above code is only searching through the most recent newsEntry entry for the featuredNewsItem toggle, so it is not returning anything if the most recent entry is not “featured”. If I remove the limit parameter, then it returns all the entries with the featuredNewsItem toggle turned on.
Any suggestions are appreciated!
You could try a search parameter in the channel entries tag.
https://docs.expressionengine.com/latest/channels/entries.html#searchfield_name
Something like..
{exp:channel:entries channel="newsEntry" dynamic="no" orderby="entry_date" limit="1" search:myToggleField="1"}
https://docs.expressionengine.com/latest/fieldtypes/toggle.html
“When used as a single variable, e.g. {toggle_field}, it will output a 1 for the “on” position and 0 for the “off” position. Handy if you are exporting channel data for later import or external use. Or writing templates for robot overlords”
Theoretically the channel entries loop would only show the latest, single entry that is toggled.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.