2

You probably looked at the title and said, "what the heck?".

I have this on a detail page, a loop limiting to 1, but I want to conditionally do something for the newest item. {if count == 1} won't help me here because it's already limited to 1.

{exp:channel:entries channel="insights" limit="1" dynamic="off" orderby="entry_date" sort="desc" disable="  categories|category_fields|member_data|pagination"}

{if you are the newest entry}
DO THIS
{if:else}
DO THAT
{/if}

{/exp:channel:entries}
  • I don't understand. The Channel Entries tag you're using will only ever return the newest entry (ensured by limit="1" dynamic="off" orderby="entry_date" sort="desc"), so no conditional is necessary. – Derek Hogue Jan 9 '13 at 15:20
  • What I'm trying to do here is hide the content for the newest entry, and say "this content is no available yet", but using the same template, bring in the other entries (limited to one entry, this is a detail page). I presume I can do this with two separate loops, but what conditional can check for the newest entry? – Paul Redmond Jan 9 '13 at 15:24
  • Okay, I have a workaround that will do. It will still mean I'll have to ask the client to change the status: ` {exp:channel:entries channel="insights" url_title="{freebie_3}" status="open|closed" dynamic="off" orderby="entry_date" sort="desc" disable=" categories|category_fields|member_data|pagination"} {if status == 'open'} {insights_body} {/if} {if status == 'closed'} <h4>The most recent strategic insight is available to our clients only.</h4> {/if} ` – Paul Redmond Jan 9 '13 at 15:34
  • Is there a separate viewing page for clients? If not you'd need some login logic to so non-members wouldn't see and members would. Also, you may just want to add to your status group, maybe a status="member-only" so that closed can still be used to close items. – nonprofit_tech Jan 9 '13 at 17:59
3

Use the entries tag you are using but add the parameter offset="1". So your results will start from the second entry.

http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#offset

{exp:channel:entries channel="insights" limit="1" dynamic="off" orderby="entry_date" sort="desc" offset="1" disable="  categories|category_fields|member_data|pagination"}

   DO STUFF

{/exp:channel:entries}

Additional... Looking at the comments on the original question you seem to have expanded the scope to include a restriction on what a visitor sees based on their member group.

Assuming your registered member group id is, say, 6 you would simply use a conditional to check the member group then either include or exclude the offset="1" parameter on your entries tag.

{if member_group=="6"}
    {exp:channel:entries channel="insights" limit="1" dynamic="off" orderby="entry_date" sort="desc"}
{if:else}
    {exp:channel:entries channel="insights" limit="1" offset="1" dynamic="off" orderby="entry_date" sort="desc"}
{/if}

This will show the most recent entry to registered members but show the second entry to non-registered visitors. No need to create special statuses or anything like that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.