Home > Software Related > PHP Fusion Mod: Only Show Utilized News Categories

PHP Fusion Mod: Only Show Utilized News Categories

It annoyed me that when the News List is selected in PHP Fusion, you get the whole list of news categories with their images, regardless of whether they have any news associated with them. This means that people have to scroll through all categories to see what news is available. Other PHP Fusion sites did the same thing. I was amazed no one had done anything about it.

I wanted to fix things so that only news categories with news would be displayed with their news items listed. The file I had to modify for this was news_cat.php in PHP Fusion’s root directory.

Basically, what I did was add an SQL query on the “news” database table that is based on the current news-category ID being processed. Then I have an “if” statement that checks that the current news category ID is present. I don’t care what the number is; I just want to check whether the “news” table has an entry with that category. If it’s present, normal processing continues; if not, than everything is skipped.

Most of this file consists of an “if-else” statement beginning with “if (isset($cat_id))”. The code I needed to modify was what immediately followed the latter “else” part of this statement, within a “while” loop. As you can see I’ve coloured my added code blue.

} else {
$res = 0;
$result = dbquery(”SELECT * FROM “.$db_prefix.”news_cats ORDER BY news_cat_id”);

if (dbrows($result)) {
echo “<table cellpadding=’0′ cellspacing=’1′ width=’100%’ class=’tbl-border’>\n”;
while ($data = dbarray($result)) {

$myresult = dbquery(”SELECT * FROM “.$db_prefix.”news WHERE news_cat=’”.$data['news_cat_id'].”‘ ORDER BY news_datestamp DESC LIMIT 20″);
$mycheck = dbarray($myresult);

if ($mycheck['news_cat']) {

$rows = dbcount(”(news_id)”, “news”, “news_cat=’”.$data['news_cat_id'].”‘ AND “.groupaccess(’news_visibility’).” AND (news_start=’0′||news_start<=”.time().”) AND (news_end=’0′||news_end>=”.time().”)”);
echo “<tr>\n<td width=’150′ class=’tbl1′ style=’vertical-align:top’><img src=’”.IMAGES_NC.$data['news_cat_image'].”‘ alt=’”.$data['news_cat_name'].”‘><br><br>\n”;
echo “<b>”.$locale['401'].”</b> “.$data['news_cat_name'].”<br>\n<b>”.$locale['402'].”</b> $rows</td>\n”;
echo “<td class=’tbl1′ style=’vertical-align:top’>\n”;
if ($rows) {
$result2 = dbquery(”SELECT * FROM “.$db_prefix.”news WHERE news_cat=’”.$data['news_cat_id'].”‘ AND “.groupaccess(’news_visibility’).” AND (news_start=’0′||news_start<=”.time().”) AND (news_end=’0′||news_end>=”.time().”) ORDER BY news_datestamp DESC LIMIT 10″);

while ($data2 = dbarray($result2)) {
echo “<img src=’”.THEME.”images/bullet.gif’ alt=”> <a href=’news.php?readmore=”.$data2['news_id'].”‘>”.$data2['news_subject'].”</a><br>\n”;
}
if ($rows > 10) echo “<div style=’text-align:right’><img src=’”.THEME.”images/bullet.gif’ alt=”> <a href=’”.FUSION_SELF.”?cat_id=”.$data['news_cat_id'].”‘>”.$locale['405'].”</a></div>\n”;
} else {
echo “<img src=’”.THEME.”images/bullet.gif’ alt=”> “.$locale['404'].”\n”;

}

}
}
$res = 1;
}

Note that the end bracket of my “if” statement is the forth one above, just before the closing brackets of the existing code’s “if” statement and “while” loop.

Categories: Software Related Tags:
  1. No comments yet.
  1. No trackbacks yet.