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 Hyperlink display of Categories with Article count
Sallyc
Posted on 01 Mar 2011, 21:53:59

Access: Member
Total Posts: 61
Joined: 2011-02-25

I was talking about this elsewhere and thought I'd post it for anyone else who wants to do this.

The Wiki page has how to Display Categories with Article Count but I wanted this list to be in a sidebar, hyperlinked so you could click on them and see only those articles. My son modified the Wiki and other code for me (I'm not that smart:redface:)

Here's how to do it.

On your news page put:

Code:
<?php
if( isset($_GET['cattodisplay']) ) {
  
$cat[] = urldecode( $_GET['cattodisplay'] );
}
include 
'news/index.php';
?>



Then in the sidebar for the hyperlinked Categories (replacing yourpage.php, of course) put:

Code:
<?php
$query 
= "
SELECT
 DISTINCT(SELECT COUNT(storyid) FROM news30_groupcats WHERE type = 'news'
AND catid = news30_cats.id) AS totalposts,
 name,
 news30_cats.id as catid
FROM news30_cats
   LEFT JOIN news30_groupcats ON news30_cats.id = news30_groupcats.catid
ORDER BY news30_cats.name
"
;
$results = DataAccess::fetch($query);
foreach(
$results AS $row) {
 echo 
'<A HREF="yourpage.php?cattodisplay=' . urlencode( $row['name'] ) . '">' .$row['name'] . '</A> ('. $row['totalposts'] .' article(s))<BR />';
}
?>



Since this is only modifying your news page, it won't be affected by any upgrades.

The urlencode and urldecode were because some of my categories have an ampersand in them which was causing problems. If your category doesn't have any articles you need to add one or clicking on the link will display all the articles.

Hopefully others will find this useful.
#3272
Network-13.com © 2013