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, 2013 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, 2013 at 17:09

1 Answer 1


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

{exp:channel:entries channel="news" limit="1" category="X"}
    {if no_results}
            sql="SELECT parent_id
                FROM exp_categories
                WHERE cat_id = X"
            {embed="pages/.category_loop" cat_id="{parent_id}"}
        {embed="pages/.category_loop" cat_id="X"}

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.