1

I'd like to return entries from a specific channel, but what i'd like to do is ONLY show entries from a child category first, but if there are none, then show entries from the child's parent category.

Is this possible?

  • 1
    At the point in your template where you want to loop through the entries, do you already have BOTH the child and parent category IDs? E.g., hard-coded, or via an embed variable? – Jay F Sep 9 '13 at 16:35
  • The approach in @RobsonSobral's answer is a good/simple one--he accounts for the case where you know only the child category ID. – Jay F Sep 9 '13 at 17:09
2

Put your loop on a embed and call it at this way:

{exp:channel:entries channel="news" limit="1" category="X"}
    {if no_results}
        {exp:query
            sql="SELECT parent_id
                FROM exp_categories
                WHERE cat_id = X"
        }
            {embed="pages/.category_loop" cat_id="{parent_id}"}
        {/exp:query}
    {/if}
        {embed="pages/.category_loop" cat_id="X"}
{/exp:channel:entries}
| 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.