Is There Anyway to Select a Primary Related Item in Playa?

1

We were using Solspace's Related Entries before switching to Pixel & Tonic's Playa after an upgrade to EE2. Related Entries had an option to designate a 'primary entry' of the related entries. We used code, like below, to select a single record out of the related items for 'showcasing':

{exp:related_entries:entries main_only="yes"}

    <div class="primary">
    <div class="must-read"></div>

    <h3 class="title"><a href="{if series_title_link !=""}{series_title_link}{if:else}{comment_url_title_auto_path}{/if}" title="{title}">{title}</a></h3>

    {!-- Updated: 5 May 2012, Stylistic Change to Read More --}
    <p>{exp:word_limit total="30"}{summary}{/exp:word_limit}</p><p class="readmore"><a href="{series_title_link}" title="Read More">Read Now &raquo;</a></p></div>
    </div>
    <hr />

{/exp:related_entries:entries}

Is there any method to do this in Playa? or would I need to create a second Playa field, where just a single related item is added?

nonprofit_tech

Posted 2013-01-30T12:19:05.307

Reputation: 4 819

Answers

5

If you do not specify orderby and sort parameters on the playa tags, the order in which they are displayed is the one in which they are displayed in the drop panes interface in the CP.

Code

{exp:channel:entries channel="mainchannel" limit="1"}

    ... entry stuff ...

    {exp:playa:children channel="relatedchannel" status="open"}

        {!-- Capture the first item in the playa drop pane interface --}
        {if count == 1}
            <h3>Related items</h3>
            <div class="must-read">
                <h4>{title}</h4>
                ... related entry stuff ...
            </div>
        {if:else}
            {!-- Capture the rest of the items in the playa drop pane interface --}
            <div class="normal">
                <h4>{title}</h4>
                ... related entry stuff ...
            </div>
        {/if}

        {if no_results}<p>nothing to see here, move on.</p>{/if}

    {/exp:playa:children}

{/exp:channel:entries}

Jérôme Coupé

Posted 2013-01-30T12:19:05.307

Reputation: 2 483

This was the ticket. Of course, I can't recall which items were originally consider the main item, but I can instruct the client to go back and make the main item the first item in the list. Thanks! – nonprofit_tech – 2013-01-30T16:02:01.407

Glad it helped. You could use the same kind of conditionnal logic and check the value of a custom field in the Playa children as well if you need something more complex down the road. – Jérôme Coupé – 2013-01-30T19:48:05.693

1

Could you use the order in which the items are presented in the playa field as the determining factor? the first item for example gets featured? This assumes you don't need that order represented in some other fashion.

Jean St-Amand

Posted 2013-01-30T12:19:05.307

Reputation: 3 370

That's an interesting idea. I'll have to see. Are related items re-orderable? I'd need to check if you can you even limit the display of child records, to like limit="1" or limit="5", as well. – nonprofit_tech – 2013-01-30T12:40:30.893

Well apparently limit="1" does work, but I need to figure out how Playa is ordering items, because it doesn't seem to be related to the order in the add box. I'll check-in later. – nonprofit_tech – 2013-01-30T12:51:48.297

2Playa does indeed order them by the order you selected them in the fieldtype. (Unless you use the orderby parameter in your template) You can drag to reorder entries in the fieldtype. – Jason Varga – 2013-01-30T13:31:00.053