For cases like this, the <mt:setvarblock> tag in combination with the <mt:loop> tag can do miracles. Let's look at an example:
Born at LeWeb... (2) Why you shouldn't edit Movable Type's database directly (0) Integrating Google maps into Movable Type, without using plugins (0) Making a search go directly to an entry if there is only one result (0) Movable Type 5.01 is out, find out what you can do with it (0) Using Movable Type tags inside other Movable Type tags (0)
<mt:entries lastn="999">
<mt:setvarblock name="theentry">
<li><a href="mt:entrypermalink"><mt:entrytitle> (<mt:entrycommentcount>)</a>
</mt:setvarblock>
<mt:setvarblock name="theentries{$theentry}"><mt:entrycommentcount></mt:setvarblock>
</mt:entries>
<mt:setvarblock name="theentry">
<li><a href="mt:entrypermalink"><mt:entrytitle> (<mt:entrycommentcount>)</a>
</mt:setvarblock>
<mt:setvarblock name="theentries{$theentry}"><mt:entrycommentcount></mt:setvarblock>
</mt:entries>
Basically this creates an array ("theentries", with links to the various entries as keys, and the number of comments as values. Now to display this array, we can use a loop tag:
<mt:loop name="theentries" sort_by="value numeric reverse">
<mt:var name="__key__">
</mt:loop>​
<mt:var name="__key__">
</mt:loop>​
Note how the array is sorted by value instead of by key (which is more common). But in this case, we have to store the links as the keys and the counts as values since the links are unique while the counts may not be.
The result of this is a neatly sorted list of entries, along with their comment counts:
(Yes, not a lot of comments yet but this article was written when this blog was still young)
When your blog grows, you might want to modify the code for the loop a bit, so the output is limited to just the top n entries:
<mt:loop name="theentries" sort_by="value numeric reverse">
<mt:if name="__counter__" lt="4"><mt:var name="__key__"></mt:if>
</mt:loop>​
<mt:if name="__counter__" lt="4"><mt:var name="__key__"></mt:if>
</mt:loop>​
This loop will just display the three entries with the most comments, using the built-in "__counter__" variable that is available inside each loop tag.
TIP: use a smaller value for the 'lastn' attribute of the initial <mt:entries> loop if you want to avoid always having the same old entries (with lots of comments) at the top of your list.
Tweet
Excellent post. I was checking constantly this blog and I am impressed!
Very useful information specially the last part :) I care for such information a lot.
I was seeking this certain info for a long time.
Thank you and good luck.
Excellent post. I was checking constantly this blog and I am impressed!
Very useful information specially the last part :) I care for such information a lot.
I was seeking this certain info for a long time.
Thank you and good luck.
I am regular reader, how are you everybody? This piece of writing posted at this website is
truly good.
I am regular reader, how are you everybody? This piece of writing posted at this website is
truly good.
I really love your blog.. Excellent colors & theme.
Did you build this web site yourself? Please reply back
as I'm hoping to create my own personal website and would love to learn where you got this from or just what the theme is called. Appreciate it!