开发者

MovableType: Is it possible to have a rss feed for "todays" entries?

Background

Our email vendor supports rss feeds for dynamic content, which we use successfully for "daily headline" type emails. This is a great help in automating many different emails that we don't have staffing to create daily. One of our staff as requested that his daily email (which has recent headlines from his Movable Type blog) only have headlines from entries posted on that day.

My Question

Since we use Movable Type for his blog, i开发者_运维问答s there a way to generate a rss feed that only contains items posted on the current day?


Your solution can be simplified by using the "days" parameter on mt:Entries:

<?xml version="1.0" encoding="<$MTPublishCharset$>"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><$MTBlogName remove_html="1" encode_xml="1"$></title>
<link rel="alternate" type="text/html" href="<$MTBlogURL encode_xml="1"$>" />
<link rel="self" type="application/atom+xml" href="<$MTBlogURL$>atom.xml" />
<id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTDate format="%Y"$>:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$></id>
<link rel="service.post" type="application/atom+xml" href="<$MTCGIPath$><$MTAtomScript$>/weblog/blog_id=<$MTBlogID$>" title="<$MTBlogName encode_html="1"$>" />
<updated><MTEntries lastn="1"><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></MTEntries></updated>
<MTIfNonEmpty tag="MTBlogDescription"><subtitle><$MTBlogDescription remove_html="1" encode_xml="1"$></subtitle></MTIfNonEmpty>
<generator uri="http://www.sixapart.com/movabletype/">Movable Type <$MTVersion$></generator>

<MTEntries days="1">

<entry>
<title><$MTEntryTitle remove_html="1" encode_xml="1"$></title>  
<link rel="alternate" type="text/html" href="<$MTEntryPermalink encode_xml="1"$>" />
<link rel="service.edit" type="application/atom+xml" href="<$MTCGIPath$><$MTAtomScript$>/weblog/blog_id=<$MTBlogID$>/entry_id=<$MTEntryID$>" title="<$MTEntryTitle encode_html="1"$>" />
<id><$MTEntryAtomID$></id>

<published><$MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></published>
<updated><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></updated>

<summary><$MTEntryExcerpt remove_html="1" encode_xml="1"$></summary>
<author>
    <name><$MTEntryAuthorDisplayName encode_xml="1"$></name>
    <MTIfNonEmpty tag="MTEntryAuthorURL"><uri><$MTEntryAuthorURL encode_xml="1"$></uri></MTIfNonEmpty>
</author>
<MTEntryCategories>
    <category term="<$MTCategoryLabel encode_xml="1"$>" />
</MTEntryCategories>
<content type="html" xml:lang="<$MTBlogLanguage ietf="1"$>" xml:base="<$MTBlogURL encode_xml="1"$>">
<$MTEntryBody encode_xml="1"$>
<$MTEntryMore encode_xml="1"$>
</content>
</entry>

</MTEntries>

No need for checking the date yourself, this also removes the empty "entry" tags your version creates.


Okay, so i figured it out myself. First I had to create a new feed, which i named "daily.xml" and copied the default code from atom.xml into it. Then I used setvarblock to define variables for the current date and publish date. Once this was done I used if to compare the 2 variables, and show the ones that matched.

code:

<?xml version="1.0" encoding="<$MTPublishCharset$>"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
    <title><$MTBlogName remove_html="1" encode_xml="1"$></title>
    <link rel="alternate" type="text/html" href="<$MTBlogURL encode_xml="1"$>" />
    <link rel="self" type="application/atom+xml" href="<$MTBlogURL$>atom.xml" />
    <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTDate format="%Y"$>:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$></id>
    <link rel="service.post" type="application/atom+xml" href="<$MTCGIPath$><$MTAtomScript$>/weblog/blog_id=<$MTBlogID$>" title="<$MTBlogName encode_html="1"$>" />
    <updated><MTEntries lastn="1"><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></MTEntries></updated>
    <MTIfNonEmpty tag="MTBlogDescription"><subtitle><$MTBlogDescription remove_html="1" encode_xml="1"$></subtitle></MTIfNonEmpty>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type <$MTVersion$></generator>

    <MTEntries lastn="15">


    <entry>

    <!-- this sets the current date to a variable named "TodaysDate" -->
    <mt:setvarblock name="TodayDate"><$mt:Date format="%Y%m%d"></mt:setvarblock>

    <!-- this sets the entry publish date to a variable named "PublishedDate" -->       
    <mt:setvarblock name="PublishedDate"><$mt:EntryDate format="%Y%m%d"></mt:setvarblock>

    <!-- starts an IF statement comparing equality of "PublishedDate" and "TodayDate". note: for some reason the second variable needs to have an '$' added to the front --> 
    <mt:if name="PublishedDate" eq="$TodayDate">

    <!-- the rest of this (except the end of the IF statement) is copied from default template -->
    <title><$MTEntryTitle remove_html="1" encode_xml="1"$></title>  
    <link rel="alternate" type="text/html" href="<$MTEntryPermalink encode_xml="1"$>" />
    <link rel="service.edit" type="application/atom+xml" href="<$MTCGIPath$><$MTAtomScript$>/weblog/blog_id=<$MTBlogID$>/entry_id=<$MTEntryID$>" title="<$MTEntryTitle encode_html="1"$>" />
    <id><$MTEntryAtomID$></id>

    <published><$MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></published>
    <updated><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></updated>

    <summary><$MTEntryExcerpt remove_html="1" encode_xml="1"$></summary>
    <author>
        <name><$MTEntryAuthorDisplayName encode_xml="1"$></name>
        <MTIfNonEmpty tag="MTEntryAuthorURL"><uri><$MTEntryAuthorURL encode_xml="1"$></uri></MTIfNonEmpty>
    </author>
    <MTEntryCategories>
        <category term="<$MTCategoryLabel encode_xml="1"$>" />
    </MTEntryCategories>
    <content type="html" xml:lang="<$MTBlogLanguage ietf="1"$>" xml:base="<$MTBlogURL encode_xml="1"$>">
    <$MTEntryBody encode_xml="1"$>
    <$MTEntryMore encode_xml="1"$>
    </content>

    <!-- end of our IF statement -->
    </mt:if>
    </entry>


    </MTEntries>

</feed> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜