ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying One Product In Each Category

February 17, 2012 5:25pm

Subscribe [3]
  • #1 / Feb 17, 2012 5:25pm

    Gareth Redfern

    86 posts

    I know you can set a category image in EE but this requires adding the image url to the category page which is not very intuitive for a client.

    Is there a way to just display the first product from each category so long as they are in the same channel?

    Thanks,

    Gareth

  • #2 / Feb 17, 2012 10:35pm

    Bhashkar Yadav

    727 posts

    Gareth, please try like

    {exp:channel:categories}

    {exp:channel:entries channel="channel_name" limit="1" category="{category_id}”}
      {title}
    {/exp:channel:entries}

    {/exp:channel:categories}

    hope this would help you.

  • #3 / Feb 18, 2012 3:18am

    Gareth Redfern

    86 posts

    Hi Bhashkar,

    The code above didn’t work but I had a play around and got the below to work, this will display one entry for every category.

    {exp:channel:category_archive channel="products" style="linear"}
    {categories}
    {exp:channel:entries channel="products" category="{category_id}” limit=“1”}
    {title}
    {/exp:channel:entries}
    {/categories}
    {/exp:channel:category_archive}

    Now I only want the child category entries to show, I think this can only be done with a plugin like http://devot-ee.com/add-ons/child-categories, but I am struggling to understand the docs for the plugin.

  • #4 / Feb 18, 2012 5:07am

    Gareth Redfern

    86 posts

    OK so I now have a working template but you need to use the plugin above (http://devot-ee.com/add-ons/child-categories) to only display the child categories. My code looks like below:

    {exp:child_categories category_group="1" parse="inward"}

    {child_category_start}
    {exp:channel:entries channel="products" limit="1" category="{child_category_id}”}
    <li>
    {title}
    </li>
    {/exp:channel:entries}
    {child_category_end}

    {/exp:child_categories}

    You can output any channel entry fields you like which is really useful. One point to note - you have to use the parse inward parameter in order to make it work. There is more detail of this here: http://devot-ee.com/add-ons/support/child-categories/viewthread/4471.

  • #5 / Feb 18, 2012 5:25am

    Mark Bowen

    12637 posts

    Hi Gareth,

    Just wondering which version of ExpressionEngine you are running here?

    I only ask because in the latest version of 2.x you can use the File chooser in the category assignment pages to assign an image to that field nowadays.

    If you’re not on the latest version and you have to have this functionality then there are a couple of add-ons on devot-ee.com that might help here :

    Category Image Manager

    Catsh*t

    Hope that helps a bit.

    Best wishes,

    Mark

  • #6 / Feb 18, 2012 6:06am

    Gareth Redfern

    86 posts

    Wow thanks Mark, I hadn’t seen that in the latest version. I even read through the Change Log when 2.4 was released!

    I will update the site to 2.4 and use standard category image, fantastic, thank you.

    Is there a way to just display category images for the child categories, so that I wouldn’t have to use the child category plugin?

  • #7 / Feb 18, 2012 7:50am

    Bhashkar Yadav

    727 posts

    Hi Mark, thanks for sharing it. i ‘ll give it a try.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases