couchable.co New? Start Here RSS Twitter

ExpressionEngine for Beginners: Sorting and Displaying Entries

ExpressionEngine for Beginners: Sorting and Displaying Entries

The ExpressionEngine Channel Entries tag pair has a number of powerful parameters to customize the way your entries are displayed. Instead of going over the different parameters which can be found in the documentation I’ll go over some of the more useful ways of displaying entries.

Upcoming Entries

Sometimes you want to display upcoming (future) entries but not necessarily past ones. That is, things happening in the future but not anything older than the current date. So here is how we would do that:

<ul>
{exp:channel:entries channel="channel_name" sort="desc" orderby="date" start_on="{current_time format='%Y-%m-%d %H:%i'}" limit="4" show_future_entries="yes"}
<li><a href="{url_title_path=’channel/template/’}">{title}</a> - {entry_date format="%m %d"}</il>
{/exp:channel:entries}
</ul

Which will produce:

<ul>
<
li><a href="http://yoursitename.com/channel/template/url_title">Entry Title</a> - Jun 12</li>
<
li><a href="http://yoursitename.com/channel/template/url_title">Entry Title</a> - Jun 13</li>
<
li><a href="http://yoursitename.com/channel/template/url_title">Entry Title</a> - Jun 16</li>
<
li><a href="http://yoursitename.com/channel/template/url_title">Entry Title</a> - Jul 01</li>
</
ul

Going through this:

  • Sort is simple, ascending or descending order. In this case we want descending which causes the entry closest to the current date to be displayed first and the entry furthest in the future is displayed last.
  • For orderby I am using date because we want to select entries from a specific point in time
  • Start_on gives the first entry date to start with and setting it to current_time is the current date and time, which can be specified in ExpressionEngine.
  • limit sets the maximum number of entries to display, in this case four.
  • show_future_entries is required because every entry that is displayed is happening in the future

Inside the template tags a list-item with a link to the channel entry and the entry month and day are displayed.

Displaying Entries Differently

This example is good for a blog or store in which you want to display one featured entry, then the latest three entries and maybe five of the next older entries after that. To do this we’ll use the offset parameter and a custom status.

{exp:channel:entries channel="channel_name" status="featured" limit="1"}
...featured entry here
{
/exp:channel:entries}
{exp
:channel:entries channel="channel_name" limit="3"}
...the latest 3 entries
{
/exp:channel:entries}
{exp
:channel:entries channel="channel_name" offset="3" limit="5"}
...the five entries after the first 3
{
/exp:channel:entries} 

Going through this:

To set up astatus you need to first create a custom status in your ExpressionEngine control panel: Admin > Channel Administration > Statuses then apply it to your channel: Admin > Channel Administration > Channels, select Edit Group Assignments and select the Status Group. Then all you have to do is set the Status when you are creating your entry. Now any time you want to display an entry with that Status simply add the status parameter to your Channel Entries tag.

The second Channel Entries tag should be pretty straight forward.

The third Channel Entries tag displays five entries after the first three have been displayed. We can do this using the offset parameter. Offset means it ignores whatever number of entries you specify (in this example 3) and displays everything after them. We also set the limit to five.

This is a great way to customize how your entries are displayed.

Orderby

Because this parameter has so many options and is so useful I’ll go ever some of the useful ones here.

  • To create a list of the Most Commented Entries set orderby=“comment_total”
  • To display a random entry set orderby=“random”
  • To find the latest updated entries use orderby=“edit_date”
  • To display entries alphabetically by title use orderby=“title”

ExpressionEngine has some powerful built in methods of sorting and displaying entries. In a later posts I’ll expand upon this further and go over the Query Module, for an even better way to fine tuned of your content.

Read More:
some other posts you might enjoy or I thought where particularly relevant to the web design post you just read

Finding and Fixing Broken Links

There are many reasons why your website could have broken links. Finding them and fixing them could take a long time but luckily there are free services that do it pretty painlessly.

Read More

Spread the Word

Subscribe to the RSS Feed or follow @couchable on Twitter

Have something to say? Leave A Comment Below

Most Popular:
the most popular posts of the year
Couchable Huh?
what this blog is all about

Couchable is a web design blog created by Tyler Herman. Not really updated anymore because I'm busy doing freelance design work and busy launching my little WordPress theme shop Real Theme Co. You can read a little more about my at my personal site Tylerherman.com