How to show how many entries are there in a category?
Posted: 25 January 2008 11:16 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  102
Joined  06-22-2007

I’m listing the categories from a particular category group. Beside them I want to have info for how many entries are there associated for the designated category.

Profile
 
 
Posted: 25 January 2008 01:07 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005

Most likely, you want this Wiki post, but it won’t work if you are using the Core version of EE. You’d need to upgrade (buy a license). This is because it uses the query module, which doesn’t come with the Core version.

Category Count

There also is a method to show the number of entries in the CURRENT category included there. That one should work with any version of EE.

Terry

Profile
 
 
Posted: 25 January 2008 01:49 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005

I did just find a way to show the number of entries in a category listing by using an embedded template, combining a recent discovery with this information. (I’m not sure whether or not embedded templates are available in the Core version of EE.) I attempted to place this code on a single template, but it requires passing a variable to work, thus an embedded template provides the answer.

Code Snippet for Main Page

{exp:weblog:categories weblog="weblog" style="linear"} {!-- optionally include category_group=id here --}

<h2>{category_name}</h2>
{embed="weblog/_listings5" my_cat="{exp:weblog:entries limit='1'}{categories}{category_id}{/categories}{/exp:weblog:entries}"}


{
/exp:weblog:categories}

Embedded Template (called _listings5)

{exp:weblog:entries weblog="weblog" category="{embed:my_cat}" dynamic="off" orderby="title" sort="asc" }

{categories show
="{embed:my_cat}"} {!-- this deals with entries having multiple category assignments --}
{if count
== "1"}total entries= {total_results}{/if}
<p></p>
{/categories}
{
/exp:weblog:entries}


This is a mere shrinking-down of my code used in the Wiki entry “Displaying Sub-categories and Grouping Them By Custom Category Field”, and adds the snippet of code from the other wiki entry mentioned above to the embed template, which is a stripped down version not displaying any content. Hey, it works!

Terry

Profile
 
 
Posted: 25 January 2008 03:07 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  27
Joined  02-07-2003

Terry,

Embedded templates come with the Core version.

 Signature 

Michael Taylor

“braccae tuae aperiuntur”

Profile
 
 
Posted: 25 January 2008 08:50 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005

Awesome! This would work then. That’s a TON TON TON of power being offered for free in the Core if it allows embeds!

I’m fiddling with an embed inside and embed this evening to take this idea a step further. Will keep you posted!

Thanks, Michael.

Terry

Profile
 
 
Posted: 26 January 2008 05:30 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  102
Joined  06-22-2007

The Wiki article helped me a bit, but it’s not quite the result that I wanted.
Here is a screenshot of the result. I’m sure you know what I’m aiming for by looking at the image, I want for every category to show how many posts are in it. It can be done by changing the query, right?

Image Attachments
celebs-list-bad.jpg
Click thumbnail to see full-size image
Profile
 
 
Posted: 26 January 2008 09:36 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  27
Joined  02-07-2003

I tried it and must have done something wrong. Instead of showing number of posts per category, the font size for each bit of text got bigger and bigger. Even text beyond my category links.

Probably left out a bracket or something.

UPDATE:

Tried it again…I had copied it nearly unedited from the original post. Here’s where my attempt went pear shaped:

<h2>{category_name}<h2>

The heading tag wasn’t terminated! Now it makes sense why my ‘RSS’ link later in the page was over 700 pixels high. wink

 Signature 

Michael Taylor

“braccae tuae aperiuntur”

Profile
 
 
Posted: 26 January 2008 01:40 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005
braveheart - 26 January 2008 05:30 AM

The Wiki article helped me a bit, but it’s not quite the result that I wanted.
Here is a screenshot of the result. I’m sure you know what I’m aiming for by looking at the image, I want for every category to show how many posts are in it. It can be done by changing the query, right?

Actually, the pic did more to confuse me than enlighten me.

Is “Celebreties” your category, or are the categories the starlet’s names?

It seems you have the article count working for starlet’s names. And I’m counting eight articles total (two per starlet) not five, if Celebrities is the category you are showing for.

So, what are your categories again? What do you want showing where you now have “Articles 5 Articles”?

The code in the above post should do it all. You shouldn’t need the wiki article at this point.

Terry

Profile
 
 
Posted: 26 January 2008 06:03 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  102
Joined  06-22-2007

Celebrities is my Category group and the starlet’s names are actually categories. I have posts about particular celebrities and every post is associated with particular celebrity name (which is in fact a category).
So What I’m aiming here is to list the category names and show how many posts are associated for every category.

Profile
 
 
Posted: 27 January 2008 03:10 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005
Michael Taylor - 26 January 2008 09:36 AM

I tried it and must have done something wrong. Instead of showing number of posts per category, the font size for each bit of text got bigger and bigger. Even text beyond my category links.

Probably left out a bracket or something.

UPDATE:

Tried it again…I had copied it nearly unedited from the original post. Here’s where my attempt went pear shaped:

<h2>{category_name}<h2>

The heading tag wasn’t terminated! Now it makes sense why my ‘RSS’ link later in the page was over 700 pixels high. wink

Blast! I thought I had fixed that!!! (well, it is fixed now for future generations at least…) Sorry. Thanks for catching that!

Terry

Profile
 
 
Posted: 27 January 2008 03:13 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  653
Joined  06-29-2005
braveheart - 26 January 2008 06:03 PM

Celebrities is my Category group and the starlet’s names are actually categories. I have posts about particular celebrities and every post is associated with particular celebrity name (which is in fact a category).
So What I’m aiming here is to list the category names and show how many posts are associated for every category.

Well, then, that (now fixed) code above should do the trick all by itself, without any embellishments necessary. (there was an unclosed tag originally that has been fixed - try copying and pasting it as-is and tweak to match your template and template group names?)

Terry

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 77506 Total Logged-in Users: 21
Total Topics: 101526 Total Anonymous Users: 20
Total Replies: 544276 Total Guests: 271
Total Posts: 645802    
Members ( View Memberlist )