0

I am looking to cycle thru all the parent categories of a category group, show three random entries (from the products channel) from each category, then go to the next category in the group.

I'd share some code, but I don't even know where to start.

My final code that works:

{exp:channel:categories 
    style="linear" 
    category_group="2" 
    parent_only="yes"
}
    <h1>{category_name}</h1> 

    {exp:channel:entries 
        channel="products" 
        category="{category_id}" 
        limit="3"
        orderby="title"
        sort="random"
        status="open|featured"
        cache="yes"
        refresh="5"
        disable="category_fields|member_data|pagination"
    }
        <p>{title}</p>
    {/exp:channel:entries}
{/exp:channel:categories}
2

I needed this for a recipe website once and the code below seemed to do the trick:

{exp:channel:categories channel="products" style="linear" show_empty="no"}      
  <h2>{category_name}</h2>
   {exp:channel:entries channel="products" dynamic="no" limit="3" orderby="random" category="{category_id}" }                  
     {title}
   {/exp:channel:entries}
{/exp:channel:categories}

The channel param on the categories tag is required unless you only have a single channel. Multiple channels may also be specified.

see: http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html#channel

Hope this helps!

| improve this answer | |
3

Alec's method works, but it might cause very high query counts due to the way EE generates nested Channel Entries tags. Take a look at the alternative method outlined in this post from EE Add-on superhero (and parse order master) Low. It achieves the same thing, but is much more performance friendly:

http://gotolow.com/blog/nesting-tags-and-performance-in-ee

And if you're like me and not excited about futzing with PHP, have no fear. This is actually a pretty simple and flexible technique to implement even if it might not appear so on the surface.

| 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.