Movable Type Documentation > Appendices > Appendix: Template Tags

Entries

Type: block

The mt:Entries tag is one of the most basic tags you'll use in working with Movable Type. Put simply, you open and close the <mt:Entries> and </mt:Entries> tags, and in between, Movable Type will loop through all of your entries, displaying the information you've chosen in the format you desire.

Nearly every template uses mt:Entries in one way or another, and part of the reason is because this tag is so powerful -- you can add in attributes to choose exactly what entries to show on your page, and even use these attributes in combination to sort, select, and filter your entries exactly the way you prefer. Be sure to check out the examples.

A container tag which iterates over a list of published entries from a blog. The default behavior is set according to the "Entry Listing Default" and "Entry Order" controls in the Entry Settings. These settings can be overridden with the use of these optional attributes.

Contexts supported

  • Weblog
  • System

Entry Filtering Attributes

  • author - Filters the entries by the given author's username.
  • category - Filters the entries by the given category label. Multiple categories can be defined in the value of the attribute and can include boolean "AND" and "OR" logic. Boolean logic may not be mixed. For instance "Foo AND Bar OR Baz" is not permitted.
  • tag or tags - Filters the entries by the given assigned tag or a boolean logic construct. Specified in the same manner as the category attribute. See below for details.
  • days - Filters all posts less than N days old. N is a positive integer. days should be used separately from other attributes. If used with another attribute, days is ignored.
  • lastn - Display the last N posts of the blog. N is a positive integer.
  • offset - Used in coordination with lastn, starts N entries from the start of the list. N is a positive integer.
  • recently_commented_on - Display the N most recently commented-on entries. Each entry will appear in the list only once. N is a positive integer.
  • blog_ids - This attribute allows you to aggregate entries from other blogs into your mt:Entries listing. Blogs are specified by their blog IDs in a comma-delimited fashion. (e.g. <mt:Entries blog_ids="1,12,19,37,112">). A value of all expands the context to all blogs in the installation.
  • limit - used in Entry Listing archive templates. Can be a positive integer or "auto", which defaults to the "Entry Listing Default" preference in the Entry Settings.
  • unique - filters out any duplicate entries that may have been previously published on the same page using another <mt:entries> tag. Values 1 or 0.
  • id - id of an entry <mt:entries id="3">

Entry Sorting Attributes

  • sort_by - Specifies the field to sort the list by. Recognized values are:
    • title
    • author_id
    • excerpt
    • status
    • author_id
    • created_on - timetime when the entry was created. Not editable via MT user interface.
    • modified_on - timetime when the entry was last modified. Not editable via MT user interface.
    • authored_on - (default) timetime when the entry was published. Editable through the MT user interface.
  • sort_order - Specifies the sort order and overrides the General Settings. Recognized values are "ascend" and "descend"

When used as an attribute of mt:Entries in the templates, the days, lastn, and sort_order attributes override their corresponding settings in the blog's General settings menu.

Boolean logic for category and tag attributes Can do advanced boolean logic in category and tag attributes (AND, OR, NOT, parenthetical grouping). For example:

<mt:Entries category="((Cats AND Dogs) OR General) NOT Private">

Combination of attributes

  • Can combine attributes (e.g. lastn="1" category="Important")
  • Order of attributes matters (i.e. trim_to="10" words="10" is different than words="10" trim_to="10")
  • Repeated attributes are processed (i.e. regexp="[regex1]" regexp="[regex2]")

Examples

<mt:Entries>
  <mt:EntryTitle>
</mt:Entries>

This is a really simple example, but it would show all the titles for your entries in that archive. Some of the most common types of information you'd want to show in your <mt:Entries> loop is covered in the documentation for mt:EntryTitle, mt:EntryBody, mt:EntryDate, and related tags.

In the default templates for MT4, there are some tricky conditional items used within mt:Entries, but a simplified version of the default loop looks like this:

<MTEntries>
<$MTEntryTrackbackData$>
<div id="entry-<$MTEntryID$>">
    <h2 class="asset-name"><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a></h2>
    By <$MTEntryAuthorLink show_email="0"$> on <$MTEntryDate format="%x %X"$> |
    <a class="permalink" href="<$MTEntryPermalink$>">Permalink</a> | 
    <a href="<$MTEntryPermalink$>#comments">Comments (<$MTEntryCommentCount$>)</a> |
    <a href="<$MTEntryPermalink$>#trackback">TrackBacks (<$MTEntryTrackbackCount$>)</a>
    <$MTEntryBody$>
    <div class="entry-tags">
        <h4>Tags:</h4>
        <ul class="entry-tags-list">
            <li class="entry-tag">
            <MTEntryTags glue=",</li> <li>">
                <a href="<$MTTagSearchLink$>&amp;IncludeBlogs=<$MTBlogID$>" rel="tag"><$MTTagName$></a>
            </MTEntryTags>
            </li>
        </ul>
    </div>
    Continue reading <a href="<$MTEntryPermalink$>#more"><$MTEntryTitle$></a>.
</div>
</MTEntries>

A common request from users is the ability to publish a list of entries that are some how related to the current entry you are looking at. The following code sample will display a list of entries that are in the same category as the current entry:

<MTSetVarBlock name="category"><MTEntryCategory></MTSetVarBlock>
<MTEntries category="$category">
    <!-- Your Code Here -->
</MTEntries>

Related Entries

This page was last updated on 2008-04-24, 20:55.  

8 User Contributed Notes

moonpost Author Profile Page said:

Apparently there is a value that goes along with the "unique" filter. I couldn't find docs so I just guessed and if you use: unique="true" it will filter out entries already published elsewhere on the same page. Does anybody know the full info on this filter?

Byrne Reese Author Profile Page said:

@moonpost - The value for the unique attribute should be either "1" or "0". If the tag is not functioning the way you expect, please let us know.

Jay Allen Author Profile Page said:

Important note: This tag supports all of the MultiBlog template tag attributes blog_ids/include_blogs and exclude_blogs for aggregating across different blogs.

Aryo Sanjaya Author Profile Page said:

For the sorting attribute, what is the 'score' mean?

If I want to show entries with most commented order, what attributes I should be use?

Thank you.

Solomon Author Profile Page said:

Would be nice if you could use "offset" in coordination with "days" in addition to lastn.

Maurice said:

Two comments:

1) Typo in the "offset" description: "M entries" should be "N entries". (now fixed)

2) It would be useful to have "days" combined with something like "lastn" for situations where you want to highlight a recent entry, but not if it is more than x days old. If you have an alternative for such a situation, I would love to know. Thanks.

Aryo Sanjaya Author Profile Page said:

@Solomon and Maurice:

No, those attributes are to show the most recently entries.

What I want is to show the most commented entries, for example to show the entries like:

  • Entry One (15 comments)
  • Entry Two (12 comments)
  • Entry Three (8 comments)
  • and soon

Or maybe I have to find a plugin for this? or just to use this tag? but how.

Thank you for your answer anyway.

Submit a User Contributed Note

User contributed notes are a great way to share the knowledge you have gained in using Movable Type.

If you have a technical question or problem, please visit Movable Type Support.

(If you haven't left a note here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)