<mt:Entries>
A block tag which iterates over a list of published entries from a blog and outputs a selection of entries that are appropriate for the context used and the template being published.
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.
<mt:Entries>
<$mt:EntryTitle$>
<$mt:EntryBody$>
</mt:Entries>
Nearly every template uses <mt:Entries> in one way or another because this tag is so powerful. You can add in attributes to specify exactly which entries to show on your page. Attributes can be used in combination to sort, select, and filter entries exactly as desired. Be sure to check out the examples.
The default behavior is set according to the “Entry Listing Default” and “Entry Order” preferences in the Entry Settings. The attributes days, lastn, and sort_order attributes override their corresponding settings in the blog’s General settings menu.
Used without any attributes, <mt:Entries> will output entries based upon the context in which it is used:
- Index Template: recent entries as specified by the “Entry Listing Default” preference in the Entry Settings
- Archive Templates: all the entries in context of the template’s archive mapping:
- monthly: all entries for the month in context
- category: recent entries in a category
- author: recent entries by a particular author
- category-monthly: all entries in a category published in the same month
Note: author and category archive mappings are limited to the value set for “Entry Listing Default” preference in the Entry Settings. Without this default, these archives could take progressively longer and longer to publish. You can override this default with the lastn attribute.
The <mt:Entries> tag can be placed in custom modules, index templates and widgets to select content in many different ways.
The output <mt:Entries> can be affected by mt:Entry tag attributes and template tag modifiers.
Beware that the ordered combination of attribtutes and modifiers can effect the output of mt:Entries.
Attributes ¶
All <mt:Entries> attributes are optional. The most common attributes are:
authorcategorycategoriesdaysfield:basenameglueidinclude_subcategorieslastnlimitmax_scoremin_scoremax_ratemin_ratemax_countmin_countnamespaceoffsetrecently_commented_onsort_byscored_bysort_ordertagtagsunique
MultiBlog attributes ¶
author ¶
Accepts an author’s username to filter entry selection. (The username is the one you log in with, not the fancy Display Name if you’ve set that in your profile.)
<mt:Entries author="melody">
Tip: To dynamically apply the author username use variable interpolation with the
mt:EntryAuthorUsernametag (when in entry context):<$mt:EntryAuthorUsername setvar="entry_author_username"$> <mt:Entries author="$entry_author_username"> <li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li> </mt:Entries>
category ¶
This attribute allows you to filter the entries based on category assignment. The simple case is to filter for a single category, where the full category name is specified:
<mt:Entries category="Featured">
Multiple categories with the same name can be differentiated using their parent category names to be more explicit:
<mt:Entries category="News/Featured">
or
<mt:Entries category="Projects/Featured">
Advanced boolean logic is supported in category and tag attributes (AND, OR, NOT, parenthetical grouping) to include or exclude categories:
<mt:Entries category="(Family OR Pets) AND Featured">
or
<mt:Entries category="((Cats AND Dogs) OR General) AND NOT Private">
or
<mt:Entries category="NOT Family">
Category ID is also a valid value when preceded by a pound (“#”) sign.
<mt:Entries category="#33">
or
<mt:Entries category="((#31 AND #32) OR General) AND NOT #3">
categories ¶
Alias of category.
days ¶
Filters all posts less than N days old (the date when the page is published). N is a positive integer.
The days attribute should be used separately from other attributes. If used with another attribute, days is ignored.
To display all entries with a publish date in the last 10 days, use this:
<mt:Entries days="10">
Set a number of days to be the default behavior for the <mt:Entries> tag in the “Entry Listing Default” preference in the Entry Settings
field:basename ¶
Permits filtering entries based on a custom field defined (custom fields are part of the Commercial Pack in MT 4.0 and 4.1, and are built in to MT Pro from version 4.2 on.).
Select the last 5 entries that have a checkbox custom field with a basename of “subscribe” which is checked:
<mt:Entries field:subscribe="1" sort_by="authored_on" sort_order="descend" limit="5">
glue ¶
A string that is output between published entries. Use it to comma-separate items, to add spaces or tabs, or to do even more complicated things.
Output a comma-separated list of entry ids (i.e. 3,2,1):
<mt:Entries glue=","><$mt:EntryID$></mt:Entries>
id ¶
Outputs a single entry matching the given entry ID.
<mt:Entries id="33">
include_subcategories ¶
Boolean value, 1 or 0 (default). If specified in conjunction with the category (or categories) attribute, entries assigned to subcategories of the identified category/categories will be included.
lastn ¶
Display the last N posts of the blog. N is a positive integer.
This attribute implies selection of entries based on their “authored” date (“Published Date” in the app), in reverse chronological order.
Movable Type will follow the value for “Entry Listing Default” preference in the Entry Settings if this attribute is not provided.
A value of “0” (zero) will output all entries.
Publish the 5 most recent entries, ordered by their title:
<mt:Entries lastn="5" sort_by="title" sort_order="ascend">
Note: when sorting use the
limitattribute; when usinglastnit is assumed that recent entries are desired.
limit ¶
Used in Entry Listing archive templates or when sorting by a value other than by publish date. Can be a positive integer or “auto”, which defaults to the “Entry Listing Default” preference in the Entry Settings. Similar to the lastn attribute.
max_score ¶
Returns entries with a score lower than the max_score value for the given namespace (required).
min_score ¶
Returns entries with a score higher than the min_score value for the given namespace (required).
max_rate ¶
Returns entries with a rate with the highest average score for the given namespace (required).
min_rate ¶
Returns entries with the lowest average score for the given namespace (required).
max_count ¶
Returns entries with which have been scored the most number of times (with any score) for the given namespace (required).
min_count ¶
Returns entries with which have been scored the least number of times (with any score) for the given namespace (required).
namespace ¶
Used to specify which scoring framework namespace to use when sorting by score (sort_by=”score”) or filtering based by score (max_score, min_score, max_rate, min_rate, max_count, min_count).
The MT Community Pack provides a community_pack_recommend namespace, for instance, which can be used to select entries, sorting by number of “recommend” or “favorite” scores that have been submitted.
offset ¶
Used in coordination with lastn, starts N entries from the start of the list.
N is a positive integer or the keyword “auto” (if dynamic publishing has been enabled) to automatically determine the offset based on the offset query parameter for the request.
This code will place the first three entries in heading 2 tags and then place the rest in an unordered list:
<mt:Entries lastn="3">
<h2><$mt:EntryTitle$></h2>
</mt:Entries>
<ul>
<mt:Entries offset="3">
<li><$mt:EntryTitle$></li>
</mt:Entries>
<ul>
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.
<mt:Entries recently_commented_on="10">
Entries are in descending order by comment date.
sort_by ¶
Defines the data to sort entries. The default value is “authored_on”. Accepted values are:
authored_on- (default) date/time when the entry was published. Editable through the MT user interface.author_idbasenamecomment_countcreated_on- date/time when the entry was created. Not editable via MT user interface.excerptkeywordsmodified_on- date/time when the entry was last modified. Not editable via MT user interface.ping_countortrackback_countrate(requires use ofnamespaceattribute)score(requires use ofnamespaceattribute)texttext_moretitlefield:BASENAMEwhere BASENAME is the basename of a custom fieldWarning: There is a bug 98025 with this attribute as of MT4.261 that causes the
mt:Entriesloop to lose blog context when using thefield:basenamein archive entry listing templates. This issue does not exist in index templates.Workarounds have been found by using another attribute to set context:
Using the include_blogs attribute:
<$mt:blogid setvar="blog_id"$> <MTEntries sort_by="field:your_custom_field" include_blogs="$blog_id"> ... </MTEntries>or in a Category Entry Listing archive using the category attribute:
<$mt:ArchiveTitle setvar="category_label"$> <MTEntries category="$category_label" sort_by="field:your_custom_field"> ... </MTEntries>
Use the limit attribute when sorting as lastn assumes that recent entries are desired.
scored_by ¶
Allows filtering of entries that were scored by a particular user, specified by username. Requires the namespace attribute.
sort_order ¶
Accepted values are “ascend” and “descend”. Default order is the order specified for “Entry Order” in the Entry Settings. Use the limit attribute when sorting as lastn assumes that recent entries are desired.
<mt:Entries sort_order="descend">
tag ¶
Filters entries by specified tag; published and private tags are supported values. The boolean operators (AND, OR, NOT, parenthetical grouping) described for category selection are also supported for the tag attribute.
Output all entries tagged with “cats”:
<mt:Entries tag="cats">
Output the opposite (all entries that are not tagged “cats”):
<mt:Entries tag="NOT cats">
Output all entries tagged “cats” and tagged “dogs”:
<mt:Entries tag="cats AND dogs">
Output all entries tagged “cats” but not tagged “dogs”::
<mt:Entries tag="cats AND NOT dogs">
tags ¶
Alias of tag attribute.
unique ¶
Filters out entries that have been previously published on the same page using another <mt:entries> tag. Values 1 or 0 (default).
The second Entries tag will exclude any entries that are output from the first Entries tag:
<mt:Entries tag="@featured" lastn="3">
<$mt:EntryTitle$>
</mt:Entries>
<mt:Entries lastn="7" unique="1">
<$mt:EntryTitle$>
</mt:Entries>
Combination of Attributes and Modifiers ¶
Attributes can be combined to display entries such as the most recent entry in the “Important” category:
<mt:Entries lastn="1" category="Important">
Repeated modifiers are all processed:
<mt:Entries regex_replace="regex1" regex_replace="regex2">
Order of attributes and modifiers is important.
Trim to ten characters and then limit to the last 10 words:
<mt:Entries trim_to="10" words="10">
Limit to the last 10 words and then trim to 10 characters:
<mt:Entries words="10" trim_to="10">
Examples ¶
Most Recent Entries ¶
This code is typically use in an index template:
<ul>
<mt:Entries lastn="10">
<li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
<mt:Entries>
</ul>
Recently Modified Entries ¶
The 25 most recently modified entries (most recent on top) in an index template:
<ul>
<mt:Entries sort_by="modified_on" sort_order="descend" limit="25">
<li><$mt:EntryModifiedDate format="%Y-%m-%d"$> - <a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
</mt:Entries>
</ul>
Complex Example ¶
In the default templates for MT4, there are some tricky conditional items used within <mt:Entries>. 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$>&IncludeBlogs=<$MTBlogID$>" rel="tag"><$MTTagName$></a>
</MTEntryTags>
</li>
</ul>
</div>
Continue reading <a href="<$MTEntryPermalink$>#more"><$MTEntryTitle$></a>.
</div>
</MTEntries>
Related Entries by Category ¶
Display entries which are in the same category as the current entry:
<$MTEntryCategory setvar="entry_category"$>
<MTEntries category="$entry_category" glue=", ">
<a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a>
</MTEntries>
Related Entries by Tag ¶
Display entries which have the same tags as the current entry:
<mt:EntryIfTagged>
<$mt:EntryID setvar="entry_id"$>
<mt:SetVarBlock name="entry_tags"><mt:EntryTags glue=" OR "><$mt:TagName$></mt:EntryTags></mt:SetVarBlock>
<mt:SetVarBlock name="related_entries">
<mt:Entries tags="$entry_tags">
<mt:SetVarBlock name="related_entry_id"><$mt:EntryID$></mt:SetVarBlock>
<mt:Unless name="related_entry_id" eq="$entry_id">
<li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
</mt:Unless>
</mt:Entries>
</mt:SetVarBlock>
<mt:If name="related_entries">
<h2>Related Entries</h2>
<ul>
<$mt:Var name="related_entries"$>
</ul>
</mt:If>
</mt:EntryIfTagged>
Related ¶
- Entry Template Tags
- Template Loop Meta Variables offer conditionals for odd, even, first, last, and counter
moonpost
September 13, 2007 9:43 AM | Reply
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
replied to comment from moonpost
September 14, 2007 9:53 AM | Reply
@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
November 1, 2007 5:28 PM | Reply
Important note: This tag supports all of the MultiBlog template tag attributes
blog_ids/include_blogsandexclude_blogsfor aggregating across different blogs.Aryo Sanjaya
January 3, 2008 10:52 PM | Reply
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
February 1, 2008 5:26 PM | Reply
Would be nice if you could use "offset" in coordination with "days" in addition to lastn.
Maurice
February 8, 2008 11:30 AM | Reply
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
February 12, 2008 10:26 PM | Reply
@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:
Or maybe I have to find a plugin for this? or just to use this tag? but how.
Thank you for your answer anyway.
Aryo Sanjaya
February 24, 2008 9:50 AM | Reply
Ok guys, I just got the answer here:
http://www.fakejazz.com/fake/archives/2005/02/movabletypepl.php
http://openid.aol.com/studiolift
July 25, 2008 3:57 AM | Reply
This page obviously changed overnight (customfield sorting! woot!!).
Someone has removed the following:
In the event that you have two categories that have the same name that you wish to filter by, you can also specify category IDs in your logical expression, provided that the category ID is preceded by a pound ("#") sign.
Has this feature gone?
Rob Kenny
August 28, 2008 12:30 PM | Reply
auto for the Offset is case sensitive. offset="Auto" throws error, offset="auto" does not.
JonathanS
September 1, 2008 6:17 AM | Reply
Filtering on custom fields didn't behave quite how I expected from the above write-up. For example
doesn't seem to be evaluated in anblock. Thus:...doesn't work. The alternative syntax
$name, however, does work:More about this at in the forumshere.
Khoa
May 12, 2009 11:51 PM | Reply
I'm programming previous and next(Monthly) calendar, I used Entries tag and put EntryPermalink tag inside. This is codes
I want to ask every one, I have articles on month and when I click one day on month is calendar not change. Example : calendar is chosen january when I click one day on month after that calendar till not change.
abbas ?
June 3, 2009 9:15 PM | Reply
hi
i have problem whith the above code example: this code dose not work for me:
my category is : music,mobile
your code that written on above this page is:
mt:Entries category="Projects/Featured"
and my code is: mt:Entries category="music/mobile"
the both codes is same but my code dose not work and had this error:
Publish error in template 'Main Index': Error in tag: You have an error in your 'category' attribute: mobile/music
and this is picture of this error on my site: http://www.mirsoft.net/files/test/error-1.jpg
help me please thanks.
oliverh
October 9, 2009 3:24 AM | Reply
Re: 'There is a bug with this attribute as of MT4.261 that causes the mt:Entries loop to lose blog context when using the field:basename.'
This bug seems to be in MT4.25 also, for the record.
Marc Boucher
October 14, 2009 10:55 AM | Reply
Although the documentation says the days attribute will ignore the days attribute if used with another attribute my experience says otherwise, at least while using the offset attribute. I'm using offset and days together with no issues.
Mihai Bocsaru
November 6, 2009 8:33 AM | Reply
Oliver, it would be interesting if you could upgrade that v4.261 installation to v4.32 and let us know if that bug still persists, which I doubt.
Mihai Bocsaru
March 12, 2010 3:32 AM | Reply
I've just upgraded a client from v4.24 pro to v4.34 pro.
The following coding worked great:
<mt:Entries tag="@Featured" lastn="1"> ... </mt:Entries> <mt:Entries tag="@Featured" lastn="1" offset="1"> ... </mt:Entries>
Unfortunately, after the upgrade, the one with the offset attribute stopped worked. It didn't provide us any content at all.
My work around was:
<mt:Entries tag="@Featured" lastn="2"> ... </mt:Entries>
Combined with the use of:
<mt:If name="first">...<mt:Else>...</mt:If> and <mt:If name="last">...</mt:If>
The coding was complex, so I've had to use all these variables!
N.B.
In my coding above, "first" and "last" should have 2 underscores before and after each one of them, but movable type when publishing this comment would remove them and make them bold...
Make sure to restore them for this coding to produce the desired effect!
Kind Regards, Mihai Bocsaru
Daily Movable Type Consultant
Web Development - Movable Type Consulting - Six Apart Partner http://www.pro-it-service.com/
Movable Type Demo http://www.movabletypedemo.org/
highway
April 14, 2010 12:01 PM | Reply
I'm currently using MT-5.01 and I'm encountering an issue with scoring. The blogs that I have were originally in it's own web directory of the main domainname and the scoring was just fine. I recently moved the blogs to a subdomain, each in it's respective directories but now I can't get the scoring to work. Even if signed in, I don't get the ability to 'score' the articles.
David
May 16, 2010 4:17 PM | Reply
I have a photo blog where I am archiving my family photos. Because of this, the date of the entry is often well in the past. No matter what sort order I use for the atom feed, it always sorts by the entry date... which means many "newer" entries are never shown in the feed because they are pictures that were taken several years ago.
The sort order, "created_on" does work on the public index page, but the feed... no go.
http://photolinguist.net/family/
Any suggestions?
abbas ?
August 4, 2010 11:02 PM | Reply
hi how i can sort my entire in rss2 template or index.xml my feed is http://www.mirsoft.net/index.xml i use from this for feedburner to this address: http://feeds2.feedburner.com/mirsoft and now i want reduce from size this file(index.xml) how i must do it? help me please.
abbas ?
September 2, 2010 4:23 AM | Reply
hi
the (tags) address in my site is this:
http://www.mirsoft.net/cgi-bin/mt/mt-search.cgi?blog_id=1&tag=download&limit=20
how i can show my tag to this?
http://www.mirsoft.net/tags/download
i use mt 4.23 thanks
thewired
September 21, 2010 4:21 PM | Reply
The attribute include_subcategories doesn't always work properly. For example you have a parent category named Food. Under it you have a subcategory named Breakfast. Breakfast contains entries but Food does not. In this case the following tag will not work, and no entries will be listed:
<mt:Entries category="Food" include_subcategories="1"> <$mt:EntryTitle$> </mt:Entries>
Instead use:
<mt:EntriesWithSubCategories category="Food"> <$mt:EntryTitle$> </mt:EntriesWithSubCategories>
Maarten Schenk
February 1, 2011 1:55 AM | Reply
The documentation of the 'days' attribute is incorrect. It says only positive integers are allowed, but numbers with decimal points also work. I have exploited this option to show only future entries by setting it to '0.0000000000001': http://www.movabletips.com/2011/02/how-to-publish-only-future-entries-in-movable-type.html
(Setting it to zero directly won't work, as the zero value is ignored.)