1

We are having a problem limiting entries correctly. Our original code:

 {exp:channel:entries channel="daily-deals" search:monday-deal="not IS_EMPTY" parse="inward" orderby="random"}
    {if monday-deal}
    {exp:playa:children field="deal-owner" category="{segment_1_category_id}" status="Super Enhanced|Enhanced|Basic" parse="inward"}
    {exp:playa:parents channel="daily-deals"}{monday-deal}{/exp:playa:parents} - {title} - {city},{state-short}<br>
    {/exp:playa:children}
    {/if}
    {/exp:channel:entries}

The code above correctly returns the correct entry results (21 total entries) BUT we want to limit the number of results shown.

When we add limit="6" to the outer entry call as follows:

{exp:channel:entries channel="daily-deals" search:monday-deal="not IS_EMPTY" parse="inward" orderby="random" limit="6"}
{if monday-deal}
{exp:playa:children field="deal-owner" category="{segment_1_category_id}" status="Super Enhanced|Enhanced|Basic" parse="inward"}
{exp:playa:parents channel="daily-deals"}{if monday-deal}{monday-deal}{/if}{/exp:playa:parents} - {title} - {city},{state-short}<br>
{/exp:playa:children}
{/if}
{/exp:channel:entries}

THIS code returns random number of results from 2-6. I believe it is because when the outter call starts by limiting to 6 entries - not all of those 6 entries make it past the inner calls - thus a different number of results are displayed.

HOW do we return all 21 results, but only display 6 of the total results?

3
  • i think the playa:parents tag also supports the search:field="value" parameter (skip a conditional). and what fieldtype is {monday-deal}? And is daily-deals self related (parents tag on same channel?)
    – GDmac
    Apr 23, 2013 at 15:57
  • look at the template debugger and at the queries this is generating. You can try those queries in SequelPro / phpMyAdmin to see what is happening.
    – GDmac
    Apr 23, 2013 at 16:10
  • We are getting the correct results, it is just not limiting correctly. We have updated our question and used cleaner code (and tried to identify the problem clearer) here: [expressionengine.stackexchange.com/questions/9616/… Apr 23, 2013 at 16:14

2 Answers 2

1

Not sure if this will work, but you could try wrapping your template code inside the channel entries with this:

{if count <=6}

{/if}

Theoretically this should only display the first 6 results that match what you get.

1
  • +1 for going by the original question (how do we limit the output to 6 entries).
    – GDmac
    Apr 23, 2013 at 15:53
0

I'm not sure if this is directly associated with your problem but just something I notice looking at your code is that you seem to duplicate a lot of the conditional checks. If you're using search:monday-deal="not IS_EMPTY then you don't need a conditional check for {if monday-deal} as you've already checked is has something in it.

{exp:channel:entries channel="daily-deals" search:monday-deal="not IS_EMPTY" orderby="random" limit="6"}

        {exp:playa:children field="deal-owner" category="{segment_1_category_id}" status="Super Enhanced|Enhanced|Basic"}

            {exp:playa:parents channel="daily-deals"}
                {monday-deal}
            {/exp:playa:parents} - {title} - {city},{state-short}<br>

        {/exp:playa:children}

{/exp:channel:entries}

I've also stripped out the other conditional around {monday-deal} later on, but I'm not entirely sure, that one may be required. Try it and see.

I've also removed the parse="inward" tags as I'm not sure you need those either? What do you get with the above?

8
  • You are correct - there were a few redundant checks - however the issue is: Apr 22, 2013 at 22:11
  • [STEP 1] {exp:channel:entries channel="daily-deals" search:monday-deal="not IS_EMPTY" orderby="random" limit="6"} [STEP 2] {exp:playa:children field="deal-owner" [STEP 3] category="{segment_1_category_id}" status="Super Enhanced|Enhanced|Basic"} [STEP 4] {exp:playa:parents channel="daily-deals"}{monday-deal}{/exp:playa:parents} – [STEP 5] {title} - {city},{state-short}<br> {/exp:playa:children} {/exp:channel:entries} Apr 22, 2013 at 22:13
  • The ISSUE is the number of results that are returned and output in the template. Step 1 – Identifies all the deals that have Monday populated and limits to 6. [Selects ALL the deals that have something in the Monday field and then selects 6 random entries] Step 2 - Looks to the “deal-owner” field and finds the businesses associated with all the identified deals (the children of the 6 deals) Apr 22, 2013 at 22:16
  • Step 3 – Of the businesses identified in Step 2, selects those that have the matching zone to the template name (using category=”{segment_1_category_id}”) for instance the business is classified in the zone: Rapid City (url=rapid-city) and the template is www.website.com/rapid-city/deal-test Step 4 - Then displays the deal information Step 5 – And displays the business title, city and state to display within the output template. Apr 22, 2013 at 22:17
  • **The problem is that the limit function only works in step 1, but if we put the limit there, Steps 2, 3, 4 and 5 only work with the initially selected 6 random entries – thus when the records are checked against step 3, some are dropped off – resulting in the display of less than 6 entries. Apr 22, 2013 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.