I'm embedding a set of tag pairs with another set of tag pairs, but because there are two entries that meet the criteria of the outer tag pairs, EE's displaying the embedded tag pairs twice.

My code is as follows:

    {exp:channel:entries channel="property_details" dynamic="no" status="open" orderby="random" limit="3" search:featured_property="=y"}
        {if total_results < 3}

What I'm trying to do is display three 'featured' entries when three or more exist (which is relatively simply using the search parameter in the tag and then an {if total_results > 2} within the tag.

When there aren't three results, I'm trying to just pick three non-featured entries at random as display them. I've embedded a template to enable me to use a tag pair within another, but this is then displaying that embedded template twice as there are two entries that meet the out tags criteria.

Any ideas on how to make it just display the embedded template once?


You could nest another conditional:

{if total_results < 3}
  {if count==total_results}
  • That's amazing, thanks Michael! If you've got time, I'd love to understand how that works? – Tom Perkins Dec 21 '12 at 15:23
  • Sure - the count variable starts at one and increments each time the channel:entries tag loops. When it's equal to the total_results variable it means you are at the last iteration through the loop. – Michael Boyink Dec 21 '12 at 15:25
  • An alternative approach would be {if count == 1} - then it would only be true the first iteration through the loop. – Michael Boyink Dec 21 '12 at 15:26
  • That's really helpful, thank you and Happy Christmas! – Tom Perkins Dec 21 '12 at 15:31

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.