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.

Hide Entries That Have Multiple Categories

September 09, 2010 11:37am

Subscribe [2]
  • #1 / Sep 09, 2010 11:37am

    Andrew Philpott

    18 posts

    I’ve got a template using the following code:

    {exp:weblog:categories weblog="products" style="linear" parent_only="yes" show_empty="no"}
    <h4>{category_name}</h4>
    
    <p><ol class="order-form"><br />
        {exp:weblog:entries weblog="products" disable="member_data|pagination" dynamic="off" orderby="title" sort="asc" category="{category_id}"}<br />
        <li>{title}</li><br />
        {/exp:weblog:entries}<br />
    </ol><br />
    {/exp:weblog:categories}

    Does anybody know of a way to make it so that entries which have multiple categories assigned will only appear under the heading for one category?

  • #2 / Sep 09, 2010 4:58pm

    Ingmar

    29245 posts

    Unfortunately this is not a built-in option. Please consider making a Feature Request. Perhaps you could achieve what you are looking for with a custom SQL query?

  • #3 / Sep 09, 2010 5:03pm

    Andrew Philpott

    18 posts

    Sorry, forgot to post a follow-up. I was able to do this using an embed and some PHP.

    Template:

    {exp:weblog:categories weblog="products" style="linear" parent_only="yes" show_empty="no"}
    <h4>{category_name}</h4>
    
    <p>{embed="_embeds/.order-form" cat-id="{category_id}"}<br />
    {/exp:weblog:categories}

    Embed:

    <ol>
        {exp:weblog:entries weblog="products" disable="member_data|pagination" dynamic="off" orderby="title" sort="asc" category="{embed:cat-id}"}
        
        <?php $weblogCategory = "{categories limit='1'}{category_id}{/categories}";
            $category = "{embed:cat-id}";
            
        if($weblogCategory == $category){ ?>
        <li>{title}</li>
        <?php } ?>
        {/exp:weblog:entries}
    </ol>
  • #4 / Sep 09, 2010 5:17pm

    Ingmar

    29245 posts

    Cool! So you’re all set, I take it?

  • #5 / Sep 09, 2010 5:18pm

    Andrew Philpott

    18 posts

    Yep, all set. Thanks!

  • #6 / Sep 09, 2010 5:19pm

    Ingmar

    29245 posts

    Excellent. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases