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.

Listing data by field with exp:channel:entries

November 26, 2011 10:15am

Subscribe [3]
  • #1 / Nov 26, 2011 10:15am

    astuteo

    36 posts

    I have to show two lists (different markup for each) using data from the same set of entries. Is there any way to wrap it all in a single channel entries tag, but loop the two within the respective areas? In a nutshell, I need the output to be:

    <div class="photos">
        {photo}
        {photo}
        {photo}
        {photo}
        {photo}
    </div>
    
    <div class="titles">
        {title}
        {title}
        {title}
        {title}
        {title}
    </div>
  • #2 / Nov 26, 2011 12:26pm

    Rob Allen

    3105 posts

    If it’s a list of photos then I’d first do this then sprinkle some CSS on to style…

    <ul>
    {exp:channel:entries channel="channelname"}
    <li>{photo}{title}</li>
    {/exp:channel:entries}
    </ul>
  • #3 / Nov 27, 2011 8:34am

    Sean C. Smith

    3818 posts

    Astuteo,

    Yes you can. Try the code below - I’ve wrapped each of your opening and closing divs in a conditional so it only displays once.

    {if count == '1'}<div class="photos">{/if}
        {photo}
        {photo}
        {photo}
        {photo}
        {photo}
    {if count == total_results}</div>{/if}
    
    {if count == '1'}<div class="titles">{/if}
        {title}
        {title}
        {title}
        {title}
        {title}
    {if count == total_results}</div>{/if}

    Sean

  • #4 / Nov 27, 2011 11:27pm

    astuteo

    36 posts

    Sean,

    I’m looking to separate two fields entirely. From what I understand of EE, the code you posted should return something along the lines of:

    <div class="photos">
         <img> (1)
    <div class="titles">
         {title} (1)
         <img> (2)
         {title} (2)
         <img> (3)
         {title} (3)
         <img> (4)
         {title} (4)
         <img> (5)
    </div>
         {title} (5)
    </div>
  • #5 / Nov 28, 2011 7:39pm

    Sean C. Smith

    3818 posts

    Astuteo,

    I noticed a missing {/if} in my code above and have fixed it. The code should now output

    <div class="photos">
    Image 1
    Image 2
    Image 3
    Image 4
    Image 5
    </div>
    
    <div class="titles">
    Title 1
    Title 2
    Title 3
    Title 4
    Title 5
    </div>
  • #6 / Nov 30, 2011 4:01pm

    astuteo

    36 posts

    Sean,

    There must be some miscommunication. The solution you offer does not work conceptually, nor does it work in practice. I did test it and it returns exactly as I stated previously.

    Matt

  • #7 / Dec 04, 2011 1:29pm

    Sean C. Smith

    3818 posts

    Matt,

    My apologies I see what I was doing wrong here and you are correct that it will output the way you said. Unfortunately, you will need to use two separate channel entries tags in this case.

    Sean

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

ExpressionEngine News!

#eecms, #events, #releases