View Full Version : How to make a forum list?
I asked this a while back, but got no replies. So, I'll ask again...
Can someone please write for me a simple little script that will list (echo or print) a list of all the forums in the message board? Each forum should be listed as a hyperlink to that forum.
For why I need this, please look at my message board: http://www.jjr512.com/bbs/index.php
Notice that at the top of the message board, and on the top of every message board page (forum list, thread list, thread view, etc.) there are hyperlinks into each forum. Many users like to use these, because they can hop around the forums quicker with these than with anything else. I manually created these links, and I'd just like something that will do it automatically, in case my forums change.
There is an hack for that already!
But it displays a small bullet list with all forums in order like A, B, C, D.etc?
That's fine, I can work out the formatting myself, I just need the actual working part to start with. Can you point me in the right direction?
Here it is:
<?php
require("/full/path/to/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query = "SELECT * FROM forum ORDER BY title ASC";
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<FONT SIZE=\"1\" FACE=\"Verdana, Arial, Helvetica, sans-serif\"> °
<A HREF=\"http://www.extremeforums.com/forums/forumdisplay.php?forumid=$latest_array[forumid]\">$latest_array[title]</A></FONT><BR>";
}
?>
OK, that works. Now, one last question: Can you modify it so that it sorts the forums in the same order that they appear in the message board?
Actually, here's another question: Can we exclude forums that are either really Archives, or else are just closed?
Yeah I am sure you can do those things.
Umm... I meant could somebody show me how?
Here is what I wrote up. It is a little more complicated but is more customizable....
<?php
require("config.php");
//Changing these flags to Zero will change the output.
$showcat=1; // Show Categories
$showdesc=1; // Show Forum Descriptions
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$catquery=("SELECT categoryid,title FROM category WHERE displayorder <> 0 and categoryid<>5 and categoryid<>9 ORDER BY displayorder");
$catresult=mysql_query($catquery,$db);
if ($showcat==1){
while ($cat = mysql_fetch_array($catresult)) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"-1\"><a href=\"http://sitepointforums.com/index.php?categoryid=".$cat[categoryid]."\">".$cat[title]."</a></font><br>");
$forumquery=("SELECT forumid,title,description FROM forum WHERE showactive=1 and categoryid=$cat[categoryid] ORDER BY displayorder");
$forumresult=mysql_query($forumquery,$db);
while ($forum = mysql_fetch_array($forumresult)) {
if ($showdesc==1) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://sitepointforums.com/forumdisplay.php?forum=".$forum[forumid]."\">".$forum[title]."</a><br>".$forum[description]."</font><br>");
}
else {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://sitepointforums.com/forumdisplay.php?forum=".$forum[forumid]."\">".$forum[title]."</a></font><br>");
}
}
}
}
else {
$forumquery=("SELECT forumid,title,description FROM forum WHERE showactive=1 ORDER BY displayorder");
$forumresult=mysql_query($forumquery,$db);
while ($forum = mysql_fetch_array($forumresult)) {
if ($showdesc==1) {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://sitepointforums.com/forumdisplay.php?forum=".$forum[forumid]."\">".$forum[title]."</a><br>".$forum[description]."</font><br>");
}
else {
echo ("<font face=\"Arial, Helvetica, sans-serif\" size=\"-3\"><a href=\"http://sitepointforums.com/forumdisplay.php?forum=".$forum[forumid]."\">".$forum[title]."</a></font><br>");
}
}
}
?>
This code requires a custom field to be added to your Forum table... It should be:
showactive smallint(6) default 1
setting that column to zero will prevent particular forums from showing. Also if you want to exclude different categories then you can change the line:
$catquery=("SELECT categoryid,title FROM category WHERE displayorder <> 0 and categoryid<>5 and categoryid<>9 ORDER BY displayorder");
To reflect your restricted categories.
Hmm... I thought the solution would involve something similar to this piece of code:
$querylatest="SELECT * FROM thread WHERE forumid='1' OR forumid='2' OR forumid='3' OR forumid='4' OR forumid='5' OR forumid='6' OR forumid='8' OR forumid='11' OR forumid='12' OR forumid='13' ORDER BY lastpost DESC LIMIT $num_active";
That selects which forums to include (taken from the active topics hack). Now, I don't remember the exact syntax, but I thought there was a way to have a similar statement, only instead of explicitly specifying which forums to select, it could be written to select all forums except private ones. Well, I'd like to include private forums, but I thought that it could be modified so that it selected all forums except those that are off.
(I'm trying to avoid modifying the database, I haven't even backed it up yet and don't know how, and I'm uncomfortable messing with it. Besides, I think there must be a more elegant solution.)
You dont have to edit the database at all to run something like this.
how do I add this custom field with php code?
can you please include better instructions on how to install it, and what to edit?
[Edited by Scaramanga_gold on 01-01-2001 at 12:49 PM]
Originally posted by vBoard.co.uk
You dont have to edit the database at all to run something like this.
You don't but I did because I got tired of having to update this small code snippet every time we added a forum to the system. So this way, I added a couple of fields to the table and set them when I create the new forum and everything just adjusts around it.
We currently have 19 public forums and 6 private forums for community Management. There are also 9 categories. If I add more (I have two forums that could be broke up right now) then I would have to change the code, however with my method, I don't. This also makes it easy for the other Administrator who doesn't touch the code to know that things are kept up to date and allows our Network Administrator to know that the listing is correct as we want it.
p.s. The other field I added allows you to turn post counting on and off per forum.
Originally posted by Scaramanga_gold
how do I add this custom field with php code?
can you please include better instructions on how to install it, and what to edit?
[Edited by Scaramanga_gold on 01-01-2001 at 12:49 PM]
It was meant more as a starting point so that you could create your own file. Other than creating the column in the Forum table and editing the Catagory select, there isn't anything else to install.
I would suggest making the column using phpMySQLAdmin as it is easiest this way.
Originally posted by JJR512
Actually, here's another question: Can we exclude forums that are either really Archives, or else are just closed?
$query = "SELECT * FROM forum WHERE Active=1 ORDER BY title ASC";
add the WHERE Active=1 and it will only show the active forums...
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.