... with some template trickery we can go a long way, as usual:
<ul><mt:entries><mt:var name="thecount" value="0"><mt:EntryAssets><mt:setvarblock name="thecount"><mt:var name="__counter__"></mt:setvarblock></mt:EntryAssets><mt:if name="thecount" gt="1"><li>Entry <mt:entryid> has more than one asset (<mt:var name="thecount">)</li><mt:else><li>Entry <mt:entryid> has one or less assets (<mt:var name="thecount">)</li></mt:if></mt:entries></ul>​
This bit of code will produce following output:
- Entry 76 has one or less assets (1)
- Entry 71 has more than one asset (6)
- Entry 75 has one or less assets (1)
- Entry 74 has one or less assets (1)
- Entry 73 has one or less assets (1)
- Entry 70 has more than one asset (6)
- Entry 69 has one or less assets (1)
- Entry 68 has one or less assets (1)
- Entry 65 has more than one asset (4)
- Entry 64 has more than one asset (2)
As you can see, you can play with the number in the 'gt' argument, so you can test for any arbitrary number of assets.
If your goal is simply to display the first asset for each post, if one is available, then use this code:
<ul>
<mt:entries>
<mt:EntryAssets>
<mt:if name="__counter__" lt="2">
<li>First asset of entry <mt:entryid> is : <mt:asseturl></li>
</mt:if>
</mt:EntryAssets>
</mt:entries>
</ul>​
<mt:entries>
<mt:EntryAssets>
<mt:if name="__counter__" lt="2">
<li>First asset of entry <mt:entryid> is : <mt:asseturl></li>
</mt:if>
</mt:EntryAssets>
</mt:entries>
</ul>​
Both snippets use the '__counter__' variable which is available inside almost any loop in MT and which indicates the number of times we have entered he loop so far. If it is less than two, it means we are going through the loop for the first time. The result would look like this:
- First asset of entry 76 is : http://www.movabletips.com/index.png
- First asset of entry 71 is : http://www.movabletips.com/off.png
- First asset of entry 75 is : http://www.movabletips.com/cup.gif
- First asset of entry 74 is : http://www.movabletips.com/france.jpg
- First asset of entry 73 is : http://www.movabletips.com/euroflag.png
- First asset of entry 70 is : http://www.movabletips.com/ignore.jpg
- First asset of entry 69 is : http://www.movabletips.com/cashregister.jpg
- First asset of entry 68 is : http://www.movabletips.com/bug-pbmt-white.png
- First asset of entry 65 is : http://www.movabletips.com/Cloud.png
- First asset of entry 64 is : http://www.movabletips.com/moneybag.jpg
Note: if there is no asset available for a particular entry, the EntryAssets loop will not display anything.
Tweet
Leave a comment