Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums How To Display Category Post Count in Homepage
1 2
Chris
Posted on 25 Jan 2010, 00:49:47

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Are you using version 3.4? did you change the require paths to match your own?

Code:
require_once 'news/db.php';
require_once 'news/config.php';
#1734
Kaybin
Posted on 09 Jul 2010, 17:35:18

Access: Member
Total Posts: 9
Joined: 2010-01-15

Sorry for such a long delay in response and I thank you for your responses as they are pretty much all right on the money. I was still on version 3.2 and am now on 3.7. The code worked great!

However, I have a furthering question.
If I want to grab the count for each category individually, like you did, but I want all of the categories, is this possible do with this fetch statement?

Or would it be best to make a different include file for each category and assign it this way? It seems a little redundant to have to log in each time to grab a single number, but that is what would happen if I assigned multiple includes.

You can check out my site and how it is currently setup if you want. http://www.alphabluetech.com/kj2/
Thank you once again for all of your work with this news system. It is perfect for what I utilize it for.
#2651
Chris
Posted on 09 Jul 2010, 18:28:08

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Code:
<?php
require_once('news/db.php');
require_once(
'news/config.php');
$catcounts = DataAccess::fetch("SELECT DISTINCT
    (SELECT COUNT(storyid) FROM news30_groupcats WHERE type = 'news' AND catid = news30_cats.id) AS totalposts,
    name FROM news30_cats
    LEFT JOIN news30_groupcats ON news30_cats.id = news30_groupcats.catid ORDER BY news30_cats.name ASC"
);
    
foreach(
$catcounts AS $c){
    echo 
$c['totalposts'] . " - " . $c['name'] . "<br />";
}
?>


Will output the name of each category along with the amount of news articles assigned to it like so

Code:
2 - Blog
1 - Music
1 - Updates
#2652
1 2
Network-13.com © 2013