View Full Version : Displaying Threads on my Website Index (Update)
Zero 3
02-25-2009, 02:43 AM
Hi,
I just started a new website and switched over to vBulletin from phpBB. The last website I had, I was able to integrate forum posts within my site index. I used this code before: http://deceptive-logic.com/tutorial/php/topic with a little bit of tweaking. I want to do the same thing, but use vBulletin.
I forgot how to do a lot of coding, but I used to be decent with it (It's been 4 years since I last coded any time of script). If someone could please link me to a tutorial or be nice enough to place the required code I need, I would be very thankful. If you have any questions please PM me.
Thank you!
- Walter
--------------- Added 1235538702 at 1235538702 ---------------
Basically we want to integrate a particular forum/thread to show topics on our homepage. Our home page will be HTML.
Dismounted
02-25-2009, 05:47 AM
Just include global.php, and run a query to fetch this data.
$threads = $vbulletin->db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "thread
WHERE forumid = X
ORDER BY dateline DESC
LIMIT 5
");
while ($thread = $vbulletin->db->fetch_array($threads))
{
// thread data is in $thread
}
Zero 3
02-25-2009, 06:06 AM
can we get a little more clarification on this? How in fact do we run a query to fetch that data.
This is what we have so far:
LINE 50<?php include(Forum/global.php);
$threads = $vbulletin->db->query_read("
SELECT *
FROM " . blakecul_vbullet . "thread
WHERE forumid = 2
ORDER BY dateline DESC
LIMIT 5
");
while ($thread = $vbulletin->db->fetch_array($threads))
{
// thread data is in $thread
} ?>
And receiving: Parse error: syntax error, unexpected T_GLOBAL in /home/blakecul/public_html/layoutsliced.php on line 50
Dismounted
02-25-2009, 06:56 AM
You must use quotes, and include global.php like so: (This bit of code has been posted around a lot.)
$curdir = getcwd();
chdir('./forums');
require_once('./global.php');
chdir($curdir);
Zero 3
02-25-2009, 02:18 PM
Thank you! I think I'm a few steps short of getting it to work now since it's no longer stretching the tables and giving me errors. Now to get the threads to appear I assume I put something to display the threads here:
{
// thread data is in $thread
}
This is the page in particular:
http://www.ydnfutc.com/layoutsliced.php
The big white content box on the right is where the threads would be appearing. What code do I use to display $thread
Dismounted
02-26-2009, 05:46 AM
As mentioned, all the thread's data is in an array in $thread. You need to process this data to whatever way you want.
Zero 3
02-26-2009, 04:21 PM
Okay, I did an array dump. I can't find the body of the post in that array (like the stuff I'm typing right now)
What I'm trying to do is go:
"Title of thread here!" - By Walter
This is the body of the thread, the actual post itself.
What array do I need to get to gather the body of the post?
Alessandro68
02-26-2009, 09:46 PM
Well I'm a newbie to php. How would you display the data in $thread in the following loop:
while ($thread = $vbulletin->db->fetch_array($threads))
{
// display data is in $thread
} ?>
Zero 3
02-27-2009, 01:10 AM
Well, I did something called a dump, which shows you all the data inside the array. You need to replace this:
while ($thread = $vbulletin->db->fetch_array($threads))
{
// display data is in $thread
}
With this:
while ($thread = $vbulletin->db->fetch_array($threads))
{
echo "<pre>";var_dump($thread);die;
}
It's going to list a bunch of items. You need to copy that and save that information in a text document or something (to refer back to later).
For me, I needed to gather the Title of the thread and the persons name who posted the thread, so it was in the format
"Thread Title!" - By UsernameHere
The two variables for that are ['title'] and ['postusername']. Once you have the variables you need, You can gather them by using an echo function:
while ($thread = $vbulletin->db->fetch_array($threads))
{
echo $thread['title']." - By ".$thread['postusername']."<br>";
}
Basically, using the echo function, then following it with the array $thread and the variable ['title'] will give you this:
{
echo $thread['title']
}
Hope that helps! I went to http://www.phpfreaks.com to get help on this matter. They were very friendly and responded very quickly.
Alessandro68
02-27-2009, 07:03 AM
Thank you veru much, appreciated !
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.