1

I am showing entries from the same category on a single entry page.

<aside>
        <h2>Categories</h2>
        <ul>

    {exp:channel:entries
      channel="articles"
      disable="member_data|pagination|trackbacks"
      require_entry="yes"
      dynamic="off"
      related_categories_mode="on"
    }

    <li><a href="/articles/detail/{url_title}">{title}</a></li>

    {/exp:channel:entries}

        </ul>
    </aside>

All good but I only want the container to show if there are those entries. Any ideas?

Thanks!

1 Answer 1

2

You could move the wrapping html into the channel entries loop, like so:

{exp:channel:entries
  channel="articles"
  disable="member_data|pagination|trackbacks"
  require_entry="yes"
  dynamic="off"
  related_categories_mode="on"
}

{if count == 1}
  <aside>
    <h2>Categories</h2>
    <ul>
{/if}

<li><a href="/articles/detail/{url_title}">{title}</a></li>

{if count == total_results}
    </ul>
  </aside>
{/if}
{/exp:channel:entries}

If there are no results, nothing will get displayed. If you want to trigger something to happen, just use the no_results trigger:

{if no_results}{embed="inc/random_entries"}{/if}

Iain

3
  • I was so close! Thanks Iain, that works great.
    – MikeeBee
    Commented Jul 9, 2013 at 11:38
  • All good. Could you mark as answered if it has solved your question please :) Commented Jul 11, 2013 at 0:01
  • Oops apologies, done!
    – MikeeBee
    Commented Jul 18, 2013 at 8:18

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.