Help - Search - Members - Calendar
Full Version: display entry count for a single category
Movable Type Community Forum > Additional Resources > Tips and Tricks
faceless
Hi
I promiss I did search the archives...but

What I'm trying to do is display the entry count for a specific category. But all i seem to be able to do is loop through all categories and thus show several entry counts.

I'm sure this is easy but just cant find the right combination of tags.

TIA
kadyellebee
Hmmm, I don't think I've seen a method to show the count of just a single category out of the archive list.

This will show all of the categories and their counts:
CODE
| <MTCategories>
<$MTCategoryLabel$> - <$MTCategoryCount$> |
</MTCategories>


And that same thing works with MTArchiveCount.  But I can't seem to see anything that would let me only display one.

HOpefully someone else will have a good idea for you smile.gif
Kristine
faceless
thanks Kadyellebee, i hope there is a simple way.
otherwise it seems i'll need to do a nasty PHP hack.

create a set of objects (1 for each category - named the same as the categories) with a property for the entrycount, fill in these values using MT tags in my template then when the page gets called use PHP to select the count from the correct object, and write it where i want it.
Haven't tried integrating PHP into MT yet, so could well be in for a surprize.

this seems madness, especially when everything else in MT is so simple to get at.
what am i missing???
kadyellebee
Where are you gonna be using this count?  Maybe its something that can be generated in the context of an archive that would work for you.

smile.gif
Kristine
maddy
How about:
CODE
<MTEntries lastn="1" category="your_category_name">
<MTEntryCategories><MTCategoryLabel> (<MTCategoryCount>)</MTEntryCategories>
</MTEntries><br /><br />
I tested that in an index template. Don't know how it'd go down in an archive situation. The only problem I can see as it is, is if you often assign mulitply categories along with the one you want to list, in which case you'd need to pop in a value for glue in the MTEntryCategories tag. I tried out a few combinations with just MTEntryCategory, but kept getting out of context errors for MTCategoryCount. :angry:

It does depend on where you want to use it, for example, if you just want to show the number of entries in each category on it's own category archive page, you'd just need to use MTArchiveCount.

Anyway, I hope that helps? smile.gif
bmk
There are no nasty php hacks.  LOL!  They're all beautiful.  :) smile.gif smile.gif
kadyellebee
Oh, and I actually had that combination of tags in my first post, but then didn't think it made sense, so I deleted it all! LOL, thanks Maddy! You rock wink.gif

Kristine
faceless
Thanks Maddy, and the rest of you.

I didn't realise that MTCategoryCount could be placed outside of MTCategories container.

Is there such thing as a Template Tag DTD, or at least a simple list that shows all the tags, what each of their attributes can be and the allowed nesting order?

save me going down this route in future:
CODE
<?php
$catArr = array();
<MTCategories>
$catArr['<$MTCategoryLabel encode_php="q"$>'] = '<$MTCategoryCount encode_php="q"$>';
</MTCategories>
echo " TOTAL ENTRIES: ".$catArr['my target category'];
?>


Thanks again
Faceless
maddy
QUOTE
I didn't realise that MTCategoryCount could be placed outside of MTCategories container.

Is there such thing as a Template Tag DTD, or at least a simple list that shows all the tags, what each of their attributes can be and the allowed nesting order?

Neither did I until I tested it! But I guess the MTEntryCategories container has the same kind of attributes as MTCategories?

As for a list, I don't know. If so, I'd love to see it. If there isn't, it could be really handy to a heap of people! smile.gif I swear I've read this section of the manual a million times, and each time I discover something new!
faceless
I know, the way that section is written is great as an overview, but useless for reference.

Maybe someone (from the MT team) knows of a document, or could put one together.
An MT Tags DTD would be loverly. smile.gif
kadyellebee
Wow, I must say that I find the Template Tags section of the manual a terrific resource.  Because of the way the sections are divided up, its fairly easy to see the context that each tag can be used in.  For example, the manual says this in the MTEntryCategory section:
QUOTE
MTEntryCategories
A container tag representing a list of all of the categories--including the primary category--to which entry belongs. Inside of this container you can use any of the <$MTCategory*$> tags to display information about each category.


So, yeah, I just wanted to make sure that you knew that not everyone thought the manual was "useless"!  I find it very useful indeed!

Kristine
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.