View Full Version : [Mini-RELEASE v2] Print linked list of forums in any template
tubedogg
Fri 23rd Mar '01, 2:26am
LAST UPDATED 3.23.01 @ 2:42 PM Eastern
This is another request from JJR512. (Hey, he has good ideas. What can I say? ;)) It prints a list of forums, each linked to the thread list page for that forum, for use in any template. It excludes a) forums that aren't displayed (display order = 0) and b) forums that aren't allowed to have posts (i.e. categories).
There's no image as I couldn't find a good place to put it on my board (a slightly weird layout) so you can take a look at JJR's once he's implemented it if you like.
Hack version number: 0.0.2
Changes since last version (0.0.1): Now also excludes non-active forums (active=0); orders list by parent forum, then by display order.
For version: 2.0.0 beta 3 (possibly beta 1 and beta 2 also, but it is untested with these versions).
Files needed: functionsadd.txt (see attached zip file), functions.php.
Files to edit: functions.php.
Templates to edit: Depends (see instructions).
Instructions
1] Open the file functionsadd.txt from the zip file in a text editor.
2] Open functions.php (in the /admin directory) in a TEXT-ONLY editor (such as Notepad, Wordpad, Simpletext, EditPlus, TextPad, etc. DO NOT USE an HTML editor or WYSIWYG editor (such as HotDog, FrontPage, DreamWeaver, etc.) because it will in all likelyhood screw up the file. If you do use an editor such as these, I will *not* be able to support you.). Right after the "<?php", add the contents of functionsadd.txt.
3] Upload functions.php to your web server, making sure to put it in the admin directory.
3] Edit whichever template you want the forum links in by adding $forumlinks1 where you want the links to appear. It will show a list, separated by (two spaces). You can change this by editing the $forumlinks1 .="&-nbsp;&-nbsp;" line. Change &-nbsp;&-nbsp; to whatever you want to separate each forum name.
4] Save the template.
Instructions are also included in the zip file (forumlinks.txt).
FEEDBACK WANTED! :) Likes/dislikes/modification requests all accepted.
EDIT: Added "-" to the &-nbsp; to keep them from turning into spaces. (Why if HTML is disabled do they turn into spaces????)
JJR512
Fri 23rd Mar '01, 3:11am
Two problems.
1. It seemed that all forums, including inactive ones, were displayed.
2. They were ordered, aparently, by forum number, rather than by display order.
JJR512
Fri 23rd Mar '01, 3:16am
Just wanted to add, if you look at my place now, you will not see it...the feature is disabled as long as it shows the closed forums.
Nicholas Brown
Fri 23rd Mar '01, 6:35am
got a demo of this before I try it out? :D
snyx
Fri 23rd Mar '01, 7:04am
Yes demo?
tubedogg
Fri 23rd Mar '01, 1:14pm
Originally posted by JJR512
1. It seemed that all forums, including inactive ones, were displayed.
By inactive ones do you mean categories? I specfically weeded those out (candisplaythreads = 0). If you mean other inactive forums, you're gonna have to explain. :D
2. They were ordered, aparently, by forum number, rather than by display order.
Hmm. There's a way around this, but it's gonna take some more work. I should have something before the end of the day.
tubedogg
Sat 24th Mar '01, 3:20am
I updated it to v0.0.2, which fixes the problems that JJR mentioned. As for a demo, you're just gonna have to wait. :) I can't really implement it on my forum, so...Plus there's not much to see. It basically just creates a list of forums, useful if you don't want to use forumjump.
JJR512
Mon 26th Mar '01, 5:37pm
OK, now all the forums are being displayed that I want to be displayed, and the ones that shouldn't be displayed are not displayed. That, in other words, is correct. Only thing is an archive is being displayed, too, which I would prefer not to, but I guess is acceptable. Although is there a way to exclude an archive? I guess that is a forum that is closed or locked.
Now the problem is the display order.
Here is how I have my category and forum display orders set:
General: 1
Mindless Blabbering: 1
Current Events: 2
Useless Trivia: 3
Sports: 4
Entertainment: 5
Automobiles: 6
Computer Stuff: 2
Hardware: 7
Software: 8
Gaming: 9
SETI: 10
Site Related: 3
Feedback: 11
Moderator's Hideout: 12
Now for some reason, the Computer Stuff category's forums are displaying first, in order, then the Site Related category's forums are displaying, and finally the General category's forums are displaying (again, in order). So it seems that within each category, the forums are displayed in proper order, it's just that the categories are not displayed in order themselves.
JJR512
Mon 26th Mar '01, 5:46pm
OK, I don't know much about PHP or MySql, but have learned enough by applying hacks to think I can experiment a little, hopefully without making the planet explode or anything. ANYway, I know that the order in which the forums are listed are controlled by this part...
ORDER BY parentid,displayorder...which is part of the code that gets added to functions.php.
So I tried reversing them to see what would happen, so it looks like this...
ORDER BY displayorder,parentid...and now it works find. The forums are displayed in the correct order.
Now if anyone would like to see a demo, look here:
http://www.jjr512.com/forums/index.php?s=
And look just under the dark blue navigation bar. You'll see a hyperlinked list of all my active forums. To me (and my users), this is better than the forumjump feature. It's easier to use; just click a link. One step, all there is to it. The forumjump feature requires you open the drop-down box, select the forum, etc.; hardly requires a Ph.D., but still it's a few more steps.
Also, I've added it at the bottom of the page, in this case just above the dark blue navigation band. If you look at my message board, you'll see I've also added the navbar below the tables as well (the navbar is the part that shows the BBS name, the forum name, and if in a thread, the thread name, all as links, so you can go back up a level). I find the navbar (and the forumlinks from this hack) to actually be more useful at the bottom. Think about it. When you read through a thread, and read the last message, where do you end up? At the bottom. So why not put the links there, instead of making you have to scroll back up to the top.
Edited to add: I put the $forumlinks1 in the header and footer templates, so they appear on every page.
tubedogg
Mon 26th Mar '01, 5:52pm
Hi JJR :)
I've been thinking about this one and looking over the forum table again to see what I can do about it. You're right - the way you have yours set up, it works. However, on a board such as mine, I have the displayorder duplicated for each category. e.g.
General: 1
---Announcements: 1
The Real World: 2
---New Season: 1
---Old Season: 2
---Casting: 3
Road Rules: 3
---New Season: 1
---Old Season: 2
---Casting: 3
The Void: 4
---Reality Online: 1
---Off-topic rambling: 2
---Bug Reports: 3
---Testing testing: 4
(I left some off, but you get the idea.) So in that case, it wouldn't work. I'm trying to figure out a way around this - I think I'm gonna have to do some investigation of the parentlist field. I'll let y'all know when I come up with something. :)
JJR512
Mon 26th Mar '01, 6:02pm
I guess what I don't understand, then, is why were the categories shown in the wrong order in my case? "Mindless Blabbering" has a lower number than "Hardware", and the category that "MB" is in has a lower number than the category that "Hardware" is in. So regardless of if it was ordered by category first, then by forum, or just by forum, "MB" should have been first. But all the forums in the "Computer Stuff" category were displayed first, it the correct order within that category.
tubedogg
Mon 26th Mar '01, 6:32pm
Because parent id (which is equal to the forum id of the parent in question) is different from display order. On your site, General's id = 19, so for the MB forum, the parent id is 19. However, in Computer Stuff (id = 17), Hardware & Overclocking has a parent id of 17. See where I'm going? :)
I'm gonna have to figure out a way to use the parent list. But I have *no* idea how it works, at least not yet. I'm getting there. :D
JJR512
Mon 26th Mar '01, 6:49pm
Umm...I don't see where you're going, because you lost me with "General's id = 19". General has an ID of 1, and Computer Stuff has an ID of 2. Where did 19 and 17 come from?
tubedogg
Mon 26th Mar '01, 7:31pm
General has a displayorder of 1, and computer stuff has a displayorder of 2, both of which are *not* the forum id (or parent id).
OK. Ignoring displayorder for a minute:
General > forumid = 19. (any sub-forums will have a parentid of 19)
MB > forumid = 1, parentid = 19.
Computer Stuff > forumid = 17. (any sub-forums will have a parentid of 17)
Hardware & Overclocking > forumid = 3, parentid = 17.
If I order by parentid, Hardware & Overclocking (parentid=17) comes up first, then MB (parentid=19) because 17 < 19.
See now?
alhatali
Sun 13th May '01, 3:42am
I installed this hack successfully. However, I noticed that the list of forums displayed include private forums, not like the ForumJump list. It is true that when one clicks on a forum that's not allowed to see, they will get the Login In window.
Is there a way of displaying only the forums that one is allowed to see?
JJR512
Fri 21st Sep '01, 9:45pm
This is now a potential problem for me, as well. Tubedogg, do you think you can include permission-checking into this hack, so that people only see the forums they're allowed to see?
fury
Fri 21st Sep '01, 11:00pm
Cool hack, but I'll wait to use it until it doesn't display private forums
I know I could probably modify the forumjump to act the same if I had the php knowledge, but some of the members like the forum jump as a drop-down box
Hooper
Sun 21st Oct '01, 5:45pm
I installed this and it works with 2.03. I however uninstalled it for a couple reasons. As mentioned above, will you have a version of links that will allow certain forums not to be seen? And will it have a better formatting scheme? Like maybe...
Cat Name
<space>forum1
<space>forum2
and so on? or are you going to do anymore with this? It would be real nice to have an heirarchy of the forums to display.
Thanks
rylin
Sun 21st Oct '01, 7:17pm
regarding the displayorder.. if you want a simple fix,
begin by selecting everything that's at the root level (parent id -1 or 0 i believe), then you just loop through that with a while statement, doing the queries according to the current parentid.. yes, it will be slower than getting it straight from the mysqld, but it shouldn't differ too much..
example of recursiveness.. should work, except your going to have to rewrite it into actual code (mainly because i don't have the vB mysql class calls in my head atm :P)
getChildren(parentid=-1) { // if the root level isn't -1, replace it with whatever it's supposed to be
global $db (or whatever the db object is called)
run the query ("select forumid,title from forum where parentid='$parentid'");
while(row = fetch the array from the mysql result) {
echo "<a href='forumid'>title</a> ";
getChildren(forumid);
}
}
if you still need help with it, i'll take a look tomorrow and add a real code example ;)
Hooper
Sun 21st Oct '01, 8:27pm
Thank you okidoki. That was very nice. Much appreciated.
rylin
Mon 22nd Oct '01, 7:33am
real codexample ;)
function getChildren($parentid=-1) {
$res=$DB_site->query("SELECT forumid,title FROM forum WHERE parentid='$parentid' ORDER BY displayorder ASC");
while($row=$DB_site->fetch_array($res)) {
echo "<a href='forumdisplay.php?forumid=$row[forumid]'>$row[title]</a> ";
getChildren($row[forumid]);
}
}
should work reasonably fast, but of course, not as fast as pure mysql.. oh well :)
Powered by vBulletin™ Version 4.0.0 Beta 4 Copyright © 2009 vBulletin Solutions, Inc. All rights