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
Kaybin
Posted on 15 Jan 2010, 17:01:11

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

Hello,

I have a linkbox setup that will hold the links of the categories for my news articles. I would like to display the post/article count for each category next to the corresponding.

I am looking for the query statement and parameters to display this. Any help would be greatly appreciated.

-Kaybs
#1540
Chris
Posted on 15 Jan 2010, 17:14:30

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

This should do the trick.

Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';

$catname = 'Testcat'; #name of the category you want to count the articles for

$articlecount = DataAccess::fetch("SELECT COUNT(uid) AS totalarticles FROM $newsgroupcats INNER JOIN $newscats ON $newsgroupcats.catid = $newscats.id WHERE $newscats.name = ?", $catname);

$articlecount = $articlecount['0']['totalarticles'];

echo 
$articlecount;
?>

#1542
Last edited by Chris at 2010-01-15 17:21:04 Reason:
Nevil
Posted on 17 Jan 2010, 00:33:57

Access: Member
Total Posts: 32
Joined: 2010-01-08

Hi, thanks for this solution. I tried it on my website it works well except that the number of articles in each category is the reel number + 1.

Do you know where this problem come from ?

Thanks.
#1550
Chris
Posted on 17 Jan 2010, 01:08:00

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

Very strange indeed, there is no reason why it should show the article count + 1. To fix it simply change

$articlecount = $articlecount['0']['totalarticles'];

to

$articlecount = $articlecount['0']['totalarticles'] - 1;

Edit: actually, try this it may solve the problem

Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';

$catname = 'Testcat'; #name of the category you want to count the articles for

$articlecount = DataAccess::fetch("SELECT COUNT(uid) AS totalarticles FROM " . NEWS_GROUPCATS . " INNER JOIN " . NEWS_CATS . " ON " . NEWS_GROUPCATS . ".catid = " . NEWS_CATS . ".id WHERE " . NEWS_CATS . ".name = ? AND " . NEWS_GROUPCATS . ".type = ?", $catname, "news");

$articlecount = $articlecount['0']['totalarticles'];

echo 
$articlecount;
?>


#1552
Last edited by Chris at 2010-06-22 19:08:23 Reason:
Nevil
Posted on 17 Jan 2010, 01:16:04

Access: Member
Total Posts: 32
Joined: 2010-01-08

Thanks very much for your fast answer.

I tried that but the number doesn't change.
#1554
Chris
Posted on 17 Jan 2010, 01:19:14

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

If the above code doesn't change it

changing

$articlecount = $articlecount['0']['totalarticles'];

to

$articlecount = $articlecount['0']['totalarticles'] - 1;

definitely should.
#1555
Nevil
Posted on 17 Jan 2010, 01:19:52

Access: Member
Total Posts: 32
Joined: 2010-01-08

Sorry it was my fault.

This solution works perfectly.

Thank you for all your work on N-13.


#1556
Chris
Posted on 17 Jan 2010, 01:20:46

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

Quote:
Sorry it was my fault.

This solution works perfectly.

Thank you for all your work on N-13.

Awesome.
#1557
Nevil
Posted on 17 Jan 2010, 01:25:18

Access: Member
Total Posts: 32
Joined: 2010-01-08

In fact your new version of the code works perfectly too (without the "-1")

Great !
#1559
Kaybin
Posted on 24 Jan 2010, 21:52:24

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

I keep getting a blank page and then it doesn't allow the rest of my pages code to run either. I don't know what I am doing wrong. I really like the news system itself, I just wish I was a bit more function savvy with PHP.

I created a file called 'cattest.php'

I include your above code in the file. Pretty much nothing else but changing the category to the category I want.

I include that php file on my homepage and Blankness after that include. Any thoughts?
#1733
1 2
Network-13.com © 2013