0

Another question! I'm in the middle of a site redesign which has got me thinking about this.

When I am displaying multiple entries from a channel, i.e on a listing page, does the channel entries tag have to be part of a list <li> <ul> etc in order to display correctly?

In my current design I have all my listing pages as <ul> lists, but in my redesign I designed a listing page with multiple entries based on a recurring div.

Something like

<div class="container">
  <h2>Title</h2>
  <span>Date</span>
  <p>Description</p>
</div>
<div class="container">
  <h2>Title 2</h2>
  <span>Date 2</span>
  <p>Description 2</p>
</div>

Therefore if I wrapped the channel entries tag (with a limit of 10) around the first container div, and passed the fields through, would it then give me 10 repeated div's?

Not sure if this is an obvious or stupid question, but I am still learning EE, and the tuts that I followed when building all worked of lists items for multi entries.

2 Answers 2

3

This is more of an HTML question than an EE question. ExpressionEngine will return 5, 10, 20 or whatever number of entries you like, in the format that you like.

So if you want each entry returned as

<div class="container">
  <h2>Title</h2>
  <span>Date</span>
  <p>Description</p>
</div>

It will do so.

For example, here's the code we use on an image gallery:

{exp:channel:entries site="site" channel="gallery" limit="30" orderby="title" sort="asc"}

<div class="clearfix frame four columns{exp:tag:tags entry_id='{entry_id}' limit='5' orderby='total_entries' sort='desc'} {tag}{/exp:tag:tags}">
    <div class="gallery-meta">
        <h3><a href="/{image_type}/display/{url_title}/">{title}</a></h3>
        <p>{image_caption}</p>
    </div>
<img src="/images/gallery/{image_medium}" alt="{title}" />
</div>

{/exp:channel:entries}

You just have to decide which pieces of the code need to be repeated, and which go outside of the channel tag.

4

Whatever is between the {exp:channel:entries}{/exp:channel:entries} tags will be repeated for each entry.

So for this:

{exp:channel:entries channel="blog"}
  <div class="entry">{title}</div>
{/exp:channel:entries}

You'd get a <div> for each entry.

However, a common practice is to use conditionals to output stuff at the beginning and end though.

{exp:channel:entries channel="blog"}

  {if count == 1}<ul>{/if}
    <li>{title}</li>
  {if count == total_results}</ul>{/if}

  {if no_results}
    <p>There are no entries.</p>
  {/if}

{/exp:channel:entries}

This way, you have control whats at the start, end, and what happens if there are no entries.

You don't have to use lists, you can use whatever code you want.

5
  • Thanks for the input. This helps clear it up now! Although I'm a little uncertain as to part of your code there. {if count == 1}<ul>{/if} <li>{title}</li> {if count == total_results}</ul>{/if} - Im not sure what exactly this part is doing?
    – shorn
    Commented Jan 27, 2013 at 20:45
  • {count} is which entry is currently being output. So, the first entry would be 1. Which means, if its the first entry, output the <ul>. Then {total_results} is the total number of entries. So the last conditional reads: if the current entry is the last one, output a </ul>. Commented Jan 27, 2013 at 20:49
  • Oh I get it. I've got <ul>s hard coded in my current design, but see that this is a way of adding them dynamically. Thanks.
    – shorn
    Commented Jan 27, 2013 at 21:09
  • Yeah I was just trying to explain how it works. Perhaps if you didn't have any entries, you wouldn't want an empty <ul>. Just an example. Commented Jan 27, 2013 at 21:13
  • Yep, that's great. Thanks for clearing that up. Much appreciated.
    – shorn
    Commented Jan 27, 2013 at 21:31

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.