Feeds.App Tip: Conditionally Formatting Feed Content
Since Anil bestowed such high praise on me, I guess the pressure is on to live up to it.
I've been meaning to write about some of the not so apparent features in Feeds.App for a while now. A lot of effort and consideration has gone into the design of that plugin (more then anyone could possibly appreciate) and, truth be told, I've done a poor job of documenting and explaining it.
This post is mostly based on a reply I made on the Feeds.App discussion list. (No link -- I'm looking to officially phase that list out in favor of the MT community forums.)
Martin Petrov, a Feeds.App user, asked me if it was possible to show posts from the last two days instead of showing a specific number regardless of date.
The mt:feedentries does not support something like a days attribute that would allow for such filtering -- at least for now. (It's on my list of potential enhancements for later versions.)
All is not lost though. With the use of a couple of time based conditionals. From the Feeds.App template tag reference:
MTIfFeedEntryPublished [minutes= days=] A conditional tag that will display its contents if the feed entry in context was published in the defined period of time. A minute or days attribute is required.
MTIfFeedEntryUpdated [minutes= days=] A conditional tag that will display its contents if the feed entry in context has been updated in the defined period of time. A minute or days attribute is required.
Filtering on when an entry was published is most common so let's see how we'd implement what Martin is trying to do using MT4 notation:
<mt:feed uri="http://example.com/index.atom">
<mt:feedentries>
<mt:iffeedentrypublished days="2">
<!-- markup to display the feed entry here -->
</mt:iffeedentrypublished>
</mt:feedentries>
</mt:feed>
The above is a minimal example, of course. The mt:feed tagset identifies which feed we are working with. We then loop through the feed's entries using mt:feedentries tagset. Rather then displaying every feed entry we wrap its layout in the mt:iffeedentrypublished conditional that will only insert its contents if the entry was published in the past 2 days (48 hours).
This solution is less then ideal because it's more verbose then having a days attribute like mt:entries. It's also not as efficient because all the feed entries are being looped through it's just that only those made in the past 48 hours are output. One other potential problem is if there are more entries within that 48 hour period then the default value of lastn. That can be remedied by setting the lastn value to some number like 99 or other ridiculously high number. Do that it makes that looping even more inefficient though so be cautious.
Overall, this these tradeoffs have minimal impact and will get you what you want.
Martin also asked if it was possible to present a feed or entry differently if it was newly published or recently updated. Employing these same two condition tags we certainly can. This time its much more straight forward. Here is another minimal example for the display an entry differently based on publishing date:
<mt:feed uri="http://example.com/index.atom">
<ul><mt:feedentries>
<li>
<mt:iffeedentrypublished days="2"><strong></mt:iffeedentryupdated>
<!-- markup to display the feed entry here -->
<mt:iffeedentrypublished days="2"></strong></mt:iffeedentryupdated>
</li>
</mt:feedentries></ul>
</mt:feed>
In this example I'm using mt:feed and mt:feedentries as before though I've inserted some HTML for an unordered list to make this example a bit more concrete to what you might do. In this example I use the mt:iffeedentrypublished tagset to conditionally wrap the feed entry display in strong tagset.
Before closing this post out I should mentioned that you can also apply similar logic to feeds as a whole with the mt:iffeedupdated condition tagset. If works just like the previous two I discussed, it's just that you don't have to be in a feed entries context.
With these basics you can take the conditional display and formatting of content from feeds much further the just displaying links to content on other sites.

There are no comments yet. You could be the first!