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.

Only show nested list if there are more than 1 entry (conditonal question)

March 11, 2010 7:25am

Subscribe [2]
  • #1 / Mar 11, 2010 7:25am

    Mikee Bee

    179 posts

    Hi all, I have a navigation that uses the first entry in a weblog as the top level list item then using offset=“1” all following entries populate a nested list.

    {exp:weblog:entries weblog="asset-based" sort="asc" limit="1" dynamic="off"}
              <li{if segment_1 == "asset-based"} class="current"{/if}><a href="#">{pages-title}</a>
              {/exp:weblog:entries}
              {if segment_1 == "asset-based"}
                <ul class="nested">
                {exp:weblog:entries weblog="asset-based" offset="1" dynamic="off" sort="asc"}
                  <li><a href="#">{pages-title}</a></li>
                {/exp:weblog:entries}
                </ul>
               {/if}
              </li>

    Problem is, if there is only 1 entry the <ul> is still created and creates a gap.

    I tried adding count > 1 to my segment conditional (not sure if thats right btw) it didn’t work, then I realised I needed to wrap it in the entries tag so the ‘count’ had a reference.

    It didn’t like that (due to the nested entries tags I think) so I embedded the nested list like so…

    </li>
              {exp:weblog:entries weblog="asset-based" sort="asc" limit="1" dynamic="off"}
                   <li><a href="#}">{pages-title}</a>
              {/exp:weblog:entries}
              {exp:weblog:entries weblog="asset-based"}
                 {if segment_1 == "asset-based" AND count > 1}
                   {embed="includes/nav-list-item"}
                {/if}
              {/exp:weblog:entries}
    </li>

    and that jus’ plain don’t work and I’m stumped! It all works fine until I add the count > 1.

    This is the contents of the embed…

    <ul class="nested">
        {exp:weblog:entries weblog="asset-based" offset="1" dynamic="off" sort="asc"}
         <li><a href="#">{pages-title}</a></li>
        {/exp:weblog:entries}
    </ul>

    It’ll be something simple I’d wager.

    Thanks

  • #2 / Mar 11, 2010 7:33am

    H&O

    34 posts

    Something like:

    {exp:weblog:entries weblog="asset-based" sort="asc" limit="1" dynamic="off"}
    <li{if segment_1 == "asset-based"} class="current"{/if}><a href="#">{pages-title}</a>
    {/exp:weblog:entries}
    
        {if segment_1 == "asset-based"}
        
            {exp:weblog:entries weblog="asset-based" offset="1" dynamic="off" sort="asc"}
    
            {if count == 1}
            <ul class="nested">
            {/if}
                <li><a href="#">{pages-title}</a></li>
    
            {if count == total_results}
            </ul>
            {/if}
    
            {/exp:weblog:entries}
        
        {/if}
    </li>
  • #3 / Mar 11, 2010 7:56am

    Mikee Bee

    179 posts

    I would have never thought of doing it that way! Thank you. So is count not a reference to number of entries in a weblog but the number entry so you could pinpoint the 3rd, 5th entry etc?

  • #4 / Mar 11, 2010 9:25am

    H&O

    34 posts

    I would have never thought of doing it that way! Thank you. So is count not a reference to number of entries in a weblog but the number entry so you could pinpoint the 3rd, 5th entry etc?

    Jup!

  • #5 / Mar 11, 2010 9:54am

    Mikee Bee

    179 posts

    So would mine have worked if there was something that meant

    {if THERE IS MORE THAN 1 ENTRY IN THIS WEBLOG}

    ?

    Does such a thing not exist?

  • #6 / Mar 11, 2010 1:43pm

    H&O

    34 posts

    Do you mean:

    {if count >= 3}
    Do something for the 3rd entry and above
    {/if}
  • #7 / Mar 12, 2010 5:28am

    Mikee Bee

    179 posts

    Yeah, would that have worked with my original method?

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

ExpressionEngine News!

#eecms, #events, #releases