1 (edited by 2009-02-18 19:14:39)

Topic: [HACK] Count all articles in a Category

Name: Count all articles in a Category
Author: John/Will
CuteNews Compatibility: 1.3.6 - 1.4.1
Description:
Do you want a way to show your users how many articles you have in a single or multiple categories ? Thought it was impossible? NOT ANYMORE!
Instructions:

Post this at the place where you want the output to appear on your site

<?php
$active_news = file('news/data/news.txt');
$counts = array();
foreach ($active_news as $newsRaw) {
$newsProperties = explode('|', $newsRaw);
$counts[$newsProperties[6]] += 1;
}
<---OUTPUTCODE GOES HERE--->
?>


Now we'll actually show our article count
Replace

<---OUTPUTCODE GOES HERE--->


For multiple categories:

echo ''.($counts[xxx] + $counts[xxx]).' articles present';


For single categories:

echo ''.$counts[xxx].' articles present';

Now to dissect the code (My favourite part, drools)

$active_news = file('news/data/news.txt');


This tells you the directory your cutenews is (news) the data folder (data) and the news.txt file.... all this line does is read.
Be sure that path to CuteNews is correct!.

all you need to do, on both the accounts above, is replace "xxx" with the category(ies) numbers of your choice that you want the articles to count.

So for example.......If using the multiple category hack..... You choose:

Category 1 and Category 5.

Category 1 has 4 articles in it
Category 5 has 2 articles in it

The final value will be 6 articles present because the script counts 4+2=6.

For the single category, it counts articles for that category ONLY.

2 (edited by 2008-09-27 10:01:45)

Re: [HACK] Count all articles in a Category

Updated by: FUNimations
CuteNews Compatibility: 1.4.5 - * (no incompatibility reported yet)
Instructions:
The only difference is the first code block. The rest of the instructions are the same as post 1

<?php
$active_news = file('news/data/news.txt');
$counts = array();
foreach ($active_news as $newsRaw) {
$newsProperties = explode('|', $newsRaw);
$cat_array = explode(',', $newsProperties[6]);
for($t=0;$t<count($cat_array);$t++)
   $counts[$cat_array[$t]] += 1;
}
<---OUTPUTCODE GOES HERE--->
?>

Re: [HACK] Count all articles in a Category

Sorry for asking, but does this hack really work?

4 (edited by ninja007 2017-07-24 20:23:01)

Re: [HACK] Count all articles in a Category

It looks little messy and hazzy.......
Symptoms