Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 2 Years, 2 Months, 2 Weeks ago [How To?] Display threads from a specific forum on my main websites index.php
#1
Solved: 2 Years, 2 Months, 2 Weeks ago
Hi there,

I've been hunting around for guides on how to get my "news" forum posts to show up on my main index.php page and I was wondering if anyone could help me out?

I'm currently using MyBB 1.8.12 and all of the guides I've been able to track down appear to be for much earlier versions. Any help would be much appreciated.
Reply
#2
Solved: 2 Years, 2 Months, 2 Weeks ago
you can follow this method & improve depending on your requirement

you can replace WHERE 1=1 with WHERE fid = x (where x is fid number of required news forum)

if you want to select a number of forums then you can use WHERE fid IN (x,y,z) ..
Reply
#3
Solved: 2 Years, 2 Months, 2 Weeks ago
(05-30-2017, 02:50 PM).m. Wrote: you can follow this method & improve depending on your requirement

you can replace WHERE 1=1 with WHERE fid = x (where x is fid number of required news forum)

if you want to select a number of forums then you can use WHERE fid IN (x,y,z) ..

This is excellent, the only issue is that this actually only shows the post thread and not the content of the post itself. Which is what I'm aiming for.
Reply
#4
Solved: 2 Years, 2 Months, 2 Weeks ago
Try with this query:

$query = $db->query("
	SELECT t.tid, t.fid, t.uid, t.username, t.subject, t.replies, t.views, t.lastposter, p.message
	FROM ".TABLE_PREFIX."threads t
	INNER JOIN ".TABLE_PREFIX."posts p ON (p.tid=t.tid)
	WHERE t.fid='2' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
	ORDER BY t.lastpost DESC
	LIMIT 6" // Change the last digit to how many recent post you want to be shown
);

If you want the order by the date of publication of the thread (so not the last post) use in the ORDER BY keyword:

ORDER BY t.dateline DESC

To show the message, use inside the while loop:

$fetch['message']

If you want to limit the characters of the message insert inside the while loop:

$message = htmlspecialchars_uni($fetch['message']);
if(my_strlen($message) > 140) {
	$message = my_substr($message, 0, 140) . "...";
}

Replacing 140 with the maximum characters that you want.
Reply
#5
Solved: 2 Years, 2 Months, 2 Weeks ago
(05-31-2017, 12:49 AM)Mipher Wrote: Try with this query:

$query = $db->query("
	SELECT t.tid, t.fid, t.uid, t.username, t.subject, t.replies, t.views, t.lastposter, p.message
	FROM ".TABLE_PREFIX."threads t
	INNER JOIN ".TABLE_PREFIX."posts p ON (p.tid=t.tid)
	WHERE t.fid='2' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
	ORDER BY t.lastpost DESC
	LIMIT 6" // Change the last digit to how many recent post you want to be shown
);

If you want the order by the date of publication of the thread (so not the last post) use in the ORDER BY keyword:

ORDER BY t.dateline DESC

To show the message, use inside the while loop:

$fetch['message']

If you want to limit the characters of the message insert inside the while loop:

$message = htmlspecialchars_uni($fetch['message']);
if(my_strlen($message) > 140) {
	$message = my_substr($message, 0, 140) . "...";
}

Replacing 140 with the maximum characters that you want.

Absolutely perfect. This gives me the perfect baseline to get started on what I want to accomplish. I'll be sure to post my finished product (with a link to my site) in case anyone else wants to do something similar to me.

Thanks for the awesome support!
Reply
#6
Solved: 2 Years, 2 Months, 2 Weeks ago
Alright, for those of you that were wondering I was able to get this working exactly how I wanted it. It displays the subject of the post as well as the post content.

Here is the code... Thanks to everyone that helped me!

<?php
chdir("./forum/"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
global $mybb, $db, $cache, $lang, $plugins;  // Trim this list of global vars, if you want to.
?>

<?php
$query = $db->query("
    SELECT t.tid, t.fid, t.uid, t.username, t.subject, t.replies, t.views, t.lastposter, p.message
    FROM ".mybb_."threads t
    INNER JOIN ".mybb_."posts p ON (p.tid=t.tid)
    WHERE t.fid='3' AND t.visible='1'
    ORDER BY t.dateline DESC
    LIMIT 6
	"// Change the last digit to how many recent post you want to be shown
	
); 
$list = '';
    while($fetch = $db->fetch_array($query))
    {
        $list .= "<strong><a href=\"forum/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
		$list .= "".htmlspecialchars_uni($fetch['message'])."<br>";
        $poster = "<a href=\"forum/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Posted by: {$poster}<br /><br />";
    
    }
    //output
    echo $list;
?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)