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 a list of entries from the same sub-category on an entry page

July 11, 2013 6:24pm

Subscribe [2]
  • #1 / Jul 11, 2013 6:24pm

    ianryde

    112 posts

    Hi all,

    I have a channel of products with url structure:

    /products/product_url

    The products channel has the following categories assigned:

    Category Group 1
      Category 1
      Category 2
    Category Group 2
      Category 3
      Category 4

    On a product entry page, I want to list all of the products from the same category that the product is located within. Kind of an automated related products, or product range section.

    How would I go about doing this? I have tried several methods, or embedding templates, using gw:code categories and child categories. But seem to hit a brick wall.

    Thanks,
    Ian

  • #2 / Jul 11, 2013 8:39pm

    Elliot Lewis

    49 posts

    There’s always many ways to do the same thing, but using only EE features I’d use channel:entries, category tag pair and channel:category_archive. I’ve not tested this code, just output from memory and referring to the docs.

    Inside your Channel tag use an embed.

    {exp:channel:entries
    channel="products"
    limit="1"
    }
    <article>
        <h2>{title}</h2>
    <p></article></p>
    
    <p><aside><br />
    {embed="site/related_entries" cat="{categories backspace='1'}{category_id},{/categories}"}<br />
    </aside></p>
    
    <p>{/exp:channel:entries}

    Then in the embed use:

    {exp:channel:category_archive
    channel="products"
    show="{embed:cat}"
    style="nested"
    }
        {categories}
            <h3>{category_name}</h3>
    <p>    {/categories}<br />
        {entry_titles}<br />
            <a href="http://{path=SITE_INDEX}">{title}</a><br />
        {/entry_titles}<br />
    {/exp:channel:category_archive}

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

ExpressionEngine News!

#eecms, #events, #releases