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.

Wrapping channel entry tag based on number of entries

May 29, 2012 10:30pm

Subscribe [3]
  • #1 / May 29, 2012 10:30pm

    Damien Buckley

    62 posts

    I want to output this:

    <ul>
      <li>Silica Fume</li>
      <li>Fly Ash</li>
      <li>Sodium Gluconate</li>
    </ul>

    But, where there are no entries, I dont want to end up with and empty

    <ul></ul>

    and if I do this:

    <ul>
    {exp:channel:entries related_categories_mode="yes" custom_fields="yes" member_data="yes"}
            <li>{title}</li>
    {/exp:channel:entries}
    </ul>

    This is exactly what will happen.

    Some CMS have a ‘wrap’ parameter but I cant seem to find one for EE2 so at this stage I’m using

    {exp:channel:entries related_categories_mode="yes" limit="1"}
            {if total_entries !=""}
                <ul>
            {/if}
    {/exp:channel:entries}
     
    {exp:channel:entries related_categories_mode="yes" custom_fields="yes" member_data="yes"}
            <li>{title}</li>
    {/exp:channel:entries}
    
    {exp:channel:entries related_categories_mode="yes" limit="1"}
            {if total_entries !=""}
                </ul>
            {/if}
    {/exp:channel:entries}

    Surely there’s a better way of doing this? Hopefully I’m missing something.

  • #2 / May 29, 2012 11:17pm

    Manoj Thomas

    185 posts

    I didn’t test it, but I believe something like the following should do it:

    {exp:channel:entries related_categories_mode="yes" custom_fields="yes" member_data="yes"}
        {if count == '1'}
        <ul>
        {/if}
            <li>{title}</li>
        {if count == total_results AND count >= '1'}
        </ul>
        {/if}
    {/exp:channel:entries}
  • #3 / May 29, 2012 11:41pm

    Damien Buckley

    62 posts

    Yep, that does it. Thanks 😊

  • #4 / May 30, 2012 2:25pm

    Shane Eckert

    7174 posts

    Hey Damien,

    I am glad to see that Manoj was able to help out!

    Dude, Manoj, you are on fire man! How many posts have you resolved with just one answer today? A ton!

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases