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.

Is this possible somehow?

October 29, 2011 9:51am

Subscribe [7]
  • #1 / Oct 29, 2011 9:51am

    Anthony Hubbard

    8 posts

    Hey awesome EE community!

    Can someone tell me if the following is possible somehow. I’ll try to explain as simply as I can:

    I have the following code for a nav item - this one is hardcoded and is simple. The ‘ul’ items float creating 2 rows of 2 ‘li’ items.

    <ul>
     <li><a href="http://{path=sponsor/index}">Sponsor Children</a></li> 
     <li><a href="http://{path=what-we-do/projects}">Support Projects</a></li>
     </ul>
     <ul>
     <li><a href="http://{path=what-we-do/causes}">Educate About Causes</a></li>
     <li><a href="http://{path=what-we-do/solutions}">Empower Solutions</a></li>
     </ul>


    My problem is that I want to also do this with a dynamically created nav list that has ‘x’ amount of items - I want to add a ‘ul’ and close ‘ul’ every 2 ‘li’ items as in the above example:

    <ul>
     { exp:channel:entries channel="country" dynamic="no"}
         <li><a href="http://{url_title_path=where-we-work/country}">{title}</a></li>
     { /exp:channel:entries}
    </ul>

    I’ve got no idea if this is possible… could someone let me know if they have ideas.

    Cheers,

    Anthony

     

     

  • #2 / Oct 29, 2011 11:06pm

    mz91184

    100 posts

    Here is an idea, I haven’t tested it though.

    <ul>
     {exp:channel:entries channel="country" dynamic="no"}
      {if count != 1}
       {switch='<ul>|'}
      {/if}
          
      <li><a href="{url_title_path='where-we-work/country'}">{title}</a></li>
          
      {if count != total_results}
       {switch='|</ul>'}
      {/if}
     { /exp:channel:entries}
    </ul>
  • #3 / Oct 30, 2011 8:05am

    ahmad saad

    364 posts

    try this:

    {exp:channel:entries channel="country" dynamic="no" }
    {switch='<ul>| '}
    
          
      <li>{title}</li>
          
    {if count == total_results}
    </ul>
    {if:else}
       {switch=' |</ul>'}
    {/if}
    
    {/exp:channel:entries}
  • #4 / Oct 31, 2011 4:20am

    John Henry Donovan

    12339 posts

    Hi Anthony,

    Do either of the above options help you?

  • #5 / Nov 01, 2011 11:21pm

    Anthony Hubbard

    8 posts

    Hi John and other posters,

    Thanks heaps for your efforts - both ways work perfectly for my situation.

    Of course, things never seem to go right. I now need my columns to be lists of 3 items not 2 - and I cannot for the life of me work out how to change your logic to make it work. 2 seems to be easy (now that I can see the way you were thinking it through)... 3 seems to be very difficult…

    Any more thoughts?

    Thanks again for your replies.

    Cheers,

    Anthony

  • #6 / Nov 02, 2011 2:26pm

    LMO

    203 posts

    Should work if you just add a | inside your switch. Like so:

    {switch='<ul>||'} and {switch='||</ul>'}
  • #7 / Nov 03, 2011 5:22pm

    Robin Sowell

    13255 posts

    The amount of clever in this thread made my brain swell!  Anthony- you all squared away now?

  • #8 / Nov 08, 2011 2:38am

    Anthony Hubbard

    8 posts

    Wow… I just learned so much about EE just then…

    Thanks guys - it works! - once again proving how amazing this community is 😊

    Cheers,

    Anthony

  • #9 / Nov 08, 2011 7:53am

    Sue Crocker

    26054 posts

    Glad things are working for you.. Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases