1

We are building a fairly large & complex site. The problem I am running into is one of limiting. Here's what I need it to do:

There are various sectors. Each sector has a landing page. On the landing pages we display news stories relating to that particular sector. The way we do this is to use Playa in the news story entry to select the related sector(s), and then pull through the entries on the sector landing page templates like this:

{exp:channel:entries channel="news-article" dynamic="off" orderby="date" sort="desc"}
        {exp:playa:children var_prefix="news" field="news-related-sector"}
            {if {structure:page:entry_id} == {news:entry_id}}
                <article class="aside-news-listing">
                    <a href="{page_url}">
                        {if news-thumbnail}
                            <img src="{news-thumbnail:news-thumbnail}" alt="{title}" />
                        {if:elseif news-image}
                            <img src="{news-image:news-thumbnail}" alt="{title}" />
                        {/if}
                    </a>
                    <div class="article-text-block">
                        <h3><a href="{page_url}">{title}</a></h3>
                        <ul>
                            {categories}
                                <a href="{path='news/'}"><li class="sector1text">{category_name}</li></a>
                            {/categories}
                        </ul>
                        <span>{entry_date format='%d %F %Y'}</span>
                    </div>
                </article>
            {/if}
        {/exp:playa:children}
    {/exp:channel:entries}

Now this works fine - but it pulls through all news entries related to that sector, and we only want to display the latest 2.

I have tried using limit="2" on the channel entries tag and nothing displays. I'm guessing this is because it just selects the first 2 entries and never hits one that is related to the sector.

I have also tried using limit="2" on the playa children tag but all related news stories display - not limited.

I have tried using an {if count <= 2} conditiona inside and outside of the playa tag and inside the entry_id conditional and nothing is displayed in any case. I'm now out of ideas! Can anyone shed some light on this?

Thanks!

Notes: I am using EE 2.6.1 and Playa 4.4.5. I know this might not be the best way to achieve what we want to - but I didn't build it and it's what I have to work with :-P

0

I think you want to use playa:parents instead (as the news entries are the "parents" of the selected sector). I gather from your code that the landing page is a Structure page so you'll have to pass that page's entry ID directly (as don't think Playa will be able to glean it from the URL as normal).

{exp:playa:parents channel="news-article" entry_id="{structure:page:entry_id}" field="news-related-sector" limit="2" disable="member_data|pagination"}
<article class="aside-news-listing">
    <a href="{page_url}">
        {if news-thumbnail}
        <img src="{news-thumbnail:news-thumbnail}" alt="{title}" />
    {if:elseif news-image}
        <img src="{news-image:news-thumbnail}" alt="{title}" />
    {/if}
    </a>
    <div class="article-text-block">
    <h3><a href="{page_url}">{title}</a></h3>
    <ul>
        {categories}
        <a href="{path='news/'}"><li class="sector1text">{category_name}</li></a>
        {/categories}
    </ul>
    <span>{entry_date format='%d %F %Y'}</span>
    </div>
</article>
{/exp:playa:parents}
| improve this answer | |
  • Thanks very much, this worked! I would vote the answer up but it says I don't have enough reputation. Just one small problem with it is instead of showing the categories it just displays {categories} {category_name} {/categories}. Is that a quirk of using this method that you know of? – Joe Beaver Aug 19 '13 at 13:11
  • Playa auto-sets disable="categories|category_fields|member_data|pagination" by default (for performance reasons). So you need to override that by adding disable="member_data|pagination" (updated the answer to reflect that). – Derek Hogue Aug 19 '13 at 13:35
  • Thanks very much again, its now working perfectly! I appreciate it. – Joe Beaver Aug 19 '13 at 14:10

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.