We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Return Only the Most Recent Entry Inside A Conditional

How Do I?

stereoi123's avatar
stereoi123
35 posts
2 years ago
stereoi123's avatar stereoi123

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 &raquo;</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!

       
creativearc's avatar
creativearc
68 posts
2 years ago
creativearc's avatar creativearc

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.

? 2
       
stereoi123's avatar
stereoi123
35 posts
2 years ago
stereoi123's avatar stereoi123

Thank you! This worked great.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.