PDA

View Full Version : How do I add the numer of articles...


fjeldseth
03-08-2005, 12:09 PM
How can I add the numer of articles so it's shown behind each category?

Example.

Brewing Articles (5)
Brewing Clubs (0)
Brewing Traing (3)


Thanks.

Chris S
03-10-2005, 01:12 AM
Hey,

Where did you want this to show up? At the top of the page where it shows subcategories or somewhere else ?

How can I add the numer of articles so it's shown behind each category?

Example.

Brewing Articles (5)
Brewing Clubs (0)
Brewing Traing (3)


Thanks.

alanp
03-10-2005, 01:20 AM
I'd also be interested in this too! For me I'd like to see it on the 'categories' panel (the one that appears in the left column).

Chris S
03-10-2005, 01:27 AM
Hey Alan,

Hmm. We could do this easily if it was just the subcategory count you wanted, but do you want *all* subcategory counts in there?

eg
sub cat (1)
`-- sub sub cat 1 (3)
`-- sub sub cat 2 (3)

and so on...

I assume you want 7 for the count and not just 1 ?

I'd also be interested in this too! For me I'd like to see it on the 'categories' panel (the one that appears in the left column).

fjeldseth
03-10-2005, 12:42 PM
Thanks a lot Chris :)

Yes, I only need it at the top of the page where it shows the subcategories.
(Not the mainpage)

Hey,

Where did you want this to show up? At the top of the page where it shows subcategories or somewhere else ?

alanp
03-10-2005, 11:06 PM
Hey Alan,

Hmm. We could do this easily if it was just the subcategory count you wanted, but do you want *all* subcategory counts in there?

eg
sub cat (1)
`-- sub sub cat 1 (3)
`-- sub sub cat 2 (3)

and so on...

I assume you want 7 for the count and not just 1 ?
Personally I just care about the sub categories (top), I don't have anything further (although I might?). Heck I'll take anything :)

Chris S
03-14-2005, 11:39 PM
For an official change we'd have to include subcategories (which means adding a bit of new code to do it all)...

I can post a code-change for this (only one level down) but it'd come with a big caveat that it will change in the future.

Personally I just care about the sub categories (top), I don't have anything further (although I might?). Heck I'll take anything :)

alanp
03-15-2005, 02:31 AM
For an official change we'd have to include subcategories (which means adding a bit of new code to do it all)...

I can post a code-change for this (only one level down) but it'd come with a big caveat that it will change in the future.
Hey I'll take the official (or unofficial) change! Either one will work for me :)

BTW...out of curiosity when will the next major release of AL come out? A rough estimate would be great because I know development time can sometimes take a bit.

fjeldseth
03-16-2005, 08:17 AM
I can post a code-change for this (only one level down) but it'd come with a big caveat that it will change in the future.
I'll try this, and then I can change it back when the next release is out.
(I don't mind waiting if the next release is right around the corner, but
if it's not, I'll like to try it out now).

Thanks

Chris S
03-17-2005, 11:55 PM
Hey,

It's not right around the corner just yet.. so here we go.

Backup before you start!

Edit the templates/template_name/Panels/RootArticleCategoriesPanel.php file. At the bottom it has a function called '_GetCategoryList'.

Replace it (all) with the following:


function _GetCategoryList()
{
// Get a list of article categories and return them
$output = "";
$query = sprintf("select * from %scategories where ParentID=0 order by Name asc", $GLOBALS["AL_CFG"]["tablePrefix"]);
$catResult = mysql_query($query);

while($catRow = mysql_fetch_array($catResult))
{
$query = sprintf("select count(*) as count from %scategoryassociations WHERE categoryid='%s'", $GLOBALS['AL_CFG']['tablePrefix'], $catRow['CategoryID']);
$countresult = mysql_fetch_assoc(mysql_query($query));
$count = $countresult['count'];
$output .= sprintf("

<div class=\"ListItem\">
<A href='%s'>
%s (%s)
</A>
</div>

", AL_HELPER::CategoryLink($catRow["CategoryID"], $catRow["Name"]), $catRow["Name"], $count);
}

if(mysql_num_rows($catResult) == 0)
$output .= sprintf("<div>%s</div>", $GLOBALS["AL_LANG"]["hpNoCategories"]);

return $output;
}


You may need to change the Div to match your current one depending on which template you're using.

Big caveat - this only gets the top level category count and does not count subcategories! This *will* change in the future!

I'll try this, and then I can change it back when the next release is out.
(I don't mind waiting if the next release is right around the corner, but
if it's not, I'll like to try it out now).

Thanks

alanp
03-20-2005, 01:52 AM
very cool...it works :)

FYI...I just created another panel called "RootArticleCategoriesMainPanel.php" and applied that change. On the default.htm template, I added that panel....for the rest of the 'article' pages, I left the default one (with no article counts).

Panels...what a wonderful idea guys :)

Chris S
03-20-2005, 11:32 PM
Hey Alan,

Good idea.. I didn't think about doing it that way :)

The panels work quite well, very flexible actually :)

very cool...it works :)

FYI...I just created another panel called "RootArticleCategoriesMainPanel.php" and applied that change. On the default.htm template, I added that panel....for the rest of the 'article' pages, I left the default one (with no article counts).

Panels...what a wonderful idea guys :)

fjeldseth
03-22-2005, 09:05 AM
Hi Alan, this doesn't do it for me though..

I have two categories - Articles and Tutorials,
under them I have 6 sub categories in each.
(these are the ones I wanted the counting for)

But I can wait, it really isn't any rush.

Thanks anyway.

Chris S
03-23-2005, 10:29 PM
Hey,

Sorry... we'll be looking to update articlelive pretty soon with some more (smaller) features, so it's definitely on the list.

Hi Alan, this doesn't do it for me though..

I have two categories - Articles and Tutorials,
under them I have 6 sub categories in each.
(these are the ones I wanted the counting for)

But I can wait, it really isn't any rush.

Thanks anyway.

Jordie (Interspire Staff)
01-22-2006, 10:44 PM
Hey all,

Thought I'd post an update on this one. I changed the code so it will count the articles in the cateogry AND the sub categories it contains.

Follow the same instructions as Chris's, let me know if anyone gets stuck:

Edit the templates/template_name/Panels/RootArticleCategoriesPanel.php file. At the bottom it has a function called '_GetCategoryList'.

Replace it (all) with the following:

function _GetCategoryList()
{
// Get a list of article categories and return them
$output = "";
$query = sprintf("select * from %scategories where ParentID=0 order by Name asc", $GLOBALS["AL_CFG"]["tablePrefix"]);
$catResult = mysql_query($query);

while($catRow = mysql_fetch_array($catResult))
{
$query = sprintf("select count(*) as count from %scategoryassociations WHERE categoryid='%s'", $GLOBALS['AL_CFG']['tablePrefix'], $catRow['CategoryID']);
$countresult = mysql_fetch_assoc(mysql_query($query));
$count = $countresult['count'];
$count = $count + $this->_GetSubCatCount($catRow['CategoryID']);
$output .= sprintf("

<div class=\"ListItem\">
<A href='%s'>
%s
</A> (%s)
</div>

", AL_HELPER::CategoryLink($catRow["CategoryID"], $catRow["Name"]), $catRow["Name"], $count);
}

if(mysql_num_rows($catResult) == 0)
$output .= sprintf("<div>%s</div>", $GLOBALS["AL_LANG"]["hpNoCategories"]);

return $output;
}

function _GetSubCatCount($catID){
$query = sprintf("select * from %scategories where ParentID='%d' order by Name asc", $GLOBALS["AL_CFG"]["tablePrefix"],$catID);
$catResult = mysql_query($query);

while($catRow = mysql_fetch_array($catResult))
{
$query = sprintf("select count(*) as count from %scategoryassociations WHERE categoryid='%s'", $GLOBALS['AL_CFG']['tablePrefix'], $catRow['CategoryID']);
$countresult = mysql_fetch_assoc(mysql_query($query));
$count = $countresult['count'];
$countTotal = $countTotal + $count + $this->_GetSubCatCount($catRow['CategoryID']);
}
return $countTotal ;
}


Edit: Changed it per jurgennijhuis' suggestion below.

jurgennijhuis
01-23-2006, 07:52 PM
Very nice mod! I made a slight change by placing the number outside the link. It looks a bit tidier in my opinion. So: <div class=\"ListItem\"><A href='%s'>%s</A> (%s)</div>

jl255
07-23-2007, 07:13 PM
the styling goes all wrong when i implement this code. How can i amend it to match the template? Also, the .php files are now found under includes/display. Is that right?