Setting up a category page count on a standard HTML page

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

Setting up a category page count on a standard HTML page

Postby Spunkmeyer » Wed Feb 14, 2007 3:00 am

Hey guys, I'm curious which method you would use to post the amount of news items in a certain category (Similar to the ezStats user interface)

Code: Select all
$ezStats_CategoryPostCount
or something similar is what I would like to use, however, how would i make that work on a standard html page that isnt linked in with Coranto in any way?

Bascially this page:http://www.advocatusdiaboli.ca/index.php?page=articles has a list of categories that correspond to categories in set up in coranto (these links lead to Slided Index files set up through Maginot). Basically I would like to have a category post count beside the category names. So for example: Machinery and Technology (2) (where 2 would be the posts in that category).

Any help would be appreciated.
"God Bless the Portable Grassy Knoll"
Spunkmeyer
 
Posts: 69
Joined: Wed Jan 10, 2007 4:36 pm
Location: Whistler, BC, Canada

Postby Dale Ray » Wed Feb 14, 2007 6:24 am

Have you looked at the NewsCounter addon? For each category you wish to count you could create a profile and have the only output be the number of items.

Another approach would be to create a profile that includes all of the categories that you want to count and sort the profile by category. Then use the isNewCategory sub to tell you when a new category has started. Combined with some perl you should be able to get a count of the items in a all of the categories included in the profile.

Code: Select all
<PerlCode>
# set the display text to null
$displayText = "";
# check to see if this is the first time through
if (not $firstPass{$ProfileName}) {
    $firstPass{$ProfileName} = 1;
    # save the value of the category into a variable to use later
    $currentCategory = $Category;
   # initialize a counter fo the total number of items processed
   $totalItems{$ProfileName} = 1;
} else {
    $firstPass{$ProfileName} = 2;
   # increment the total items counter
   ++$totalItems{$ProfileName};
}
$profileCount =  $totalItems{$ProfileName};
# test to see if the itemCounter is already set
if ( (not $itemCount{$ProfileName} || $itemCount{$ProfileName} == 0) ) {
   $itemCount{$ProfileName} = 1;
} else {
    # increment the counter
    ++$itemCount{$ProfileName};
}
#check to see if the category has changed or if we have reached the end of the last category
if ( (&isNewCategory && $firstPass{$ProfileName} != 1) || ($totalItems{$ProfileName} == $NCTotalCount{$ProfileName}) ) {
    if ($totalItems{$ProfileName} != $NCTotalCount{$ProfileName}) {
       #we counted the first item in the new category so we have to adjust the count
       --$itemCount{$ProfileName};
   }
   #make the text agree with the number
    if ($itemCount{$ProfileName} == 1) {
        $lastWord = "item";
        } else {
        $lastWord = "items";
        }
# set the text to display
$displayText = "The category $currentCategory has $itemCount{$ProfileName} $lastWord.";
# set currentCategory to the new category
$currentCategory = $Category;
# reset the counter to one - remember we have processed the first item of the new category already
$itemCount{$ProfileName} = 1;
}
</PerlCode><If: Field: displayText><h1><Field: displayText></h1>
</If>

This style code will display the category name and the number of items in each category. It will not display a category that has zero items.

To work you need the Sort Orders addon (you must sort the profile by Category) and the NewsCounter addon (to tell when you have reached the end of the last category processed).

The if statement is on the same line as the closing perl code statement to prevent a bunch of blank lines in the created file. The closing if is on a new line so that there will be only one category's name and number of items on each line written to the file.

Remember that when you cut and paste from the forum you may get extra line feeds and spaces that can cause syntax errors.

You could use this method to create a list like the one you linked to by changing the html that the category names and totals are wrapped in.

The style will work with multiple profiles and will count only the categories that are included in the profile being processed.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana


Return to Customization

Who is online

Users browsing this forum: No registered users and 2 guests

cron