1

Hopefully this will just be a quick one and it maybe staring me in the face but what I want to be able to display a related testimonial of an entry.

If the testimonial has a custom status of Featured, then this will be displayed. If no testimonials have this status set, then it will revert to the latest testimonial added, presumably with a status of Open.

Can anyone help me out on how I can do this. Below is what I thought may do the trick

{if page_related_testimonials}

{page_related_testimonials 
 channel="testimonials" 
 status="Featured" 
 orderby="date" 
 sort="desc" 
 limit="2"}


    {if status=="Featured"}
    {title} 
    {if:elseif status=="open"}
    {title}
    {/if}   

{/page_related_testimonials}

 {/if}
1
  • Is this a native Relationships field or a Playa field?
    – Alex Kendrick
    Jul 9 '14 at 15:27
2

If you are only trying to display a single featured entry and if no featured then a single entry with the status of open. I'd do the this. Order your results by status and allow featured and open status entries and then sort it to to look for featured first then open. I think that might be sort="asc"

So heres what your code will look like.

{if page_related_testimonials}

  {page_related_testimonials 
      channel="testimonials" 
      status="Featured|open" 
      orderby="status|date" 
      sort="asc|desc" 
      limit="1"
   }

      {title}

   {/page_related_testimonials}

{/if}

This will return 1 entry and if an entry related to that channel has the status of Featured it will be the first entry in the data returned if there isn't an entry with Featured it will fall back to an entry related with the status of Open. I hope this helps!

5
  • Awesome, works a treat. Thanks for this, had no idea you could order by status. Has this always been the case in EE?
    – Adam
    Jul 9 '14 at 16:03
  • Not sure i know its in the docs though, I'm pretty sure i've been using it the last few years. Jul 9 '14 at 16:04
  • Good to know. I'm sure I had read it wasn't possible but it's probable that was an EEv1 issue
    – Adam
    Jul 9 '14 at 16:07
  • Well i'm glad your all set! Jul 9 '14 at 16:08
  • The conditional is unnecessary.
    – Sobral
    Jul 9 '14 at 17:05
1

I've been done this sometimes, but not using relationships. I believe the process is the same.

Try to order the entries by both date and status. Each one in one direction.

status="featured|open" orderby="status|date" sort="asc|desc" limit="1"
0

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.