Topic: How can I count the news in different categories?

How can I count the news in different categories? When I use the old hacks they doesn't work in Cute News 2.00

Re: How can I count the news in different categories?

The number of news items is counted automatically in CuteNews to form pagination. Or you can use the cn_get_news($opts); function to directly read data in the cdata/news/cat.idx I dex file.

Best regards,
CN Support team

Re: How can I count the news in different categories?

The number of news items is counted automatically in CuteNews to form pagination. Or you can use the cn_get_news($opts); function to directly read data in the cdata/news/cat.idx I dex file.


In CN 1.5.3 I used this code

<?php
$active_news = file('cdata/news.txt');
$counts = array();
foreach ($active_news as $newsRaw) {
$newsProperties = explode('|', $newsRaw);
$counts[$newsProperties[6]] += 1;
}
echo '('.$counts[2].''; if ($counts[2]<=1) { echo ' публикация)';}
else {echo ' публикации)';}
?> 

but now in cn 2.00 I couldn't understand how to change it

Re: How can I count the news in different categories?

To count news items please use the following code:

$counts = array();
$active_news = file('cdata/news/cat.idx');

foreach ($active_news as $newsRaw) {
    list($cat_id, $nids) = explode('|', $newsRaw);
    $counts[$cat_id] = count(explode(',', $nids));

Please don't forget to make news migration: https://cutephp.com/forum/index.php?showtopic=44045

Best regards,
CN Support team

Re: How can I count the news in different categories?

To count news items please use the following code:

$counts = array();
$active_news = file('cdata/news/cat.idx');

foreach ($active_news as $newsRaw) {
    list($cat_id, $nids) = explode('|', $newsRaw);
    $counts[$cat_id] = count(explode(',', $nids));

Please don't forget to make news migration: https://cutephp.com/forum/index.php?showtopic=44045


I don't have cdata/news/cat.idx

What is the problem?


I already migrate to cn 2.00

Re: How can I count the news in different categories?

I don't have cdata/news/cat.idx

What is the problem?


I already migrate to cn 2.00

Hello,

cdata/news/cat.idx will appear in your file manager (easily viewable if you are using cPanel or FTP) if you have uploaded CuteNews to your web host. I have this particular file inside my web host.

What Support_Team means is not for you to migrate from 1.53 to 2.0 again. Please check out the link he provided for you, he meant to tell you that if you are updating CuteNews via GitHub, you will need to use the news migration script to bring your old news over.

Re: How can I count the news in different categories?

Hello,

cdata/news/cat.idx will appear in your file manager (easily viewable if you are using cPanel or FTP) if you have uploaded CuteNews to your web host. I have this particular file inside my web host.

What Support_Team means is not for you to migrate from 1.53 to 2.0 again. Please check out the link he provided for you, he meant to tell you that if you are updating CuteNews via GitHub, you will need to use the news migration script to bring your old news over.

No, I can't find this file. I updated my CN from zip file. I haven't used GitHub. My old news, users and templates  are in the new version, but I can't find ths file anywhere.

Re: How can I count the news in different categories?

I install CN 2.0 to local php server
I already seen cat.idx file. In cdata/news there are many files cat.idx.xxx where xxx is a number.
But this script:


$counts = array();
$active_news = file('cdata/news/cat.idx');

foreach ($active_news as $newsRaw) {
list($cat_id, $nids) = explode('|', $newsRaw);
$counts[$cat_id] = count(explode(',', $nids));

doesn't work


I saw that cat.idx has a size 0b
others file are with diferent size but they aren't empty


What's wrong?