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?

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}
  • 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 Jan 30 '13 at 16:02
  • 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é Jan 30 '13 at 19:48
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.

  • 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 Jan 30 '13 at 12:40
  • 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 Jan 30 '13 at 12:51
  • 2
    Playa 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 Jan 30 '13 at 13: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.