1

I have a news page that should either display 10 results regardless of category or 10 results based on the category information in the URL.

My code is checking to see if there is a category url in the URL and if so performs a query with the category id to limit results to that category otherwise falls back to performing a full query.

I've tested my logic and my conditional and EE queries are working as expected but when I output the Stash list it's displaying results for entries that are not in the category.

Do I need to have two different list names?

{if segment_2_category_id != ''}

        {exp:stash:set_list name="news_list" parse_tags="yes" parse_depth="2"}
            {exp:channel:entries channel="news" status="open|featured" orderby="date" sort="desc" limit="10" category="{segment_2_category_id}"}
                {stash:item_title}{title}{/stash:item_title}
                {stash:item_url}{url_title}{/stash:item_url}
                {stash:item_date}{entry_date format="%F %d, %Y "}{/stash:item_date}
                {stash:item_copy}{news_content}{/stash:item_copy}
                {stash:item_entry_id}{entry_id}{/stash:item_entry_id}
                {exp:stash:set_list:nested name="item_media" context="{entry_id}" parse_tags="yes"}
                    {news_videos_images}
                        {stash:item_image}{image}{/stash:item_image}
                        {stash:item_video}{video}{/stash:item_video}
                    {/news_videos_images}
                {/exp:stash:set_list:nested} 
            {/exp:channel:entries}
        {/exp:stash:set_list}
    {if:else}

        {exp:stash:set_list name="news_list" parse_tags="yes" parse_depth="2"}
            {exp:channel:entries channel="news" status="open|featured" orderby="date" sort="desc" limit="10"}
                {stash:item_title}{title}{/stash:item_title}
                {stash:item_url}{url_title}{/stash:item_url}
                {stash:item_date}{entry_date format="%F %d, %Y "}{/stash:item_date}
                {stash:item_copy}{news_content}{/stash:item_copy}
                {stash:item_entry_id}{entry_id}{/stash:item_entry_id}
                {exp:stash:set_list:nested name="item_media" context="{entry_id}" parse_tags="yes"}
                    {news_videos_images}
                        {stash:item_image}{image}{/stash:item_image}
                        {stash:item_video}{video}{/stash:item_video}
                    {/news_videos_images}
                {/exp:stash:set_list:nested} 
            {/exp:channel:entries}
        {/exp:stash:set_list}
    {/if}
  • could be parse order. Have you tried 2 single if statements instead of an ifelse statement? {if segment_2_category_id != ''}---{/if} {if segment_2_category_id == ''}---{/if} – erwinheiser Feb 13 '14 at 0:15
  • Adding to erwinheiser's comment: you can also try using IfElse plugin to make your conditional parse early: devot-ee.com/add-ons/ifelse or github.com/croxton/Ifelse . You would wrap the outside conditional like {exp:ifelse parse="inward"} ...your if statements and stash lists... {/exp:ifelse} – Romans-8---31-39 Feb 13 '14 at 1:21
  • Thanks guys. erwinheiser your suggestion worked. Romans thanks for the heads up on that plugin, could come in very handy. – KoalaKid Feb 13 '14 at 2:52
  • Moving this to an answer - if you could feedback by accepting that would be much appreciated. Added a few links for further reference. – erwinheiser Feb 13 '14 at 12:29
0

Probably parse order because ifelse makes it an advanced conditional which is parsed later. Try 2 single if statements and you should be set.

{if segment_2_category_id != ''}---{/if} {if segment_2_category_id == ''}---{/if} 

For more on parse order check http://johndwells.com/blog/expressionengine-parse-order-advanced-conditionals-as-tag-parameters and @low has this excellent in-depth PDF on the issue loweblog.com/downloads/ee-parse-order.pdf‎

| improve this answer | |

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.