Forum Integration - Recent Posts on Main Site
#1
I'm not too savvy at php but using some resources from here and a bit of time I've got a great working version to integrate your main site with recent forum posts.

Although fully editable, this script will display:

Subject
Subject Creator
Replies
Views
Last Poster

a working example can be found here: http://www.backofthelandingnet.co.uk

Instructions:

1. Put this php script at the beginning of the page you want to display the recent posts on line 1 (before the HEAD tags)

<?php
chdir("pathtoforums/"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
?>

2. edit the chdir to the path to your forum

3. Insert the code below where you want recent posts to be displayed

<?php

    $query = mysql_query("
            SELECT t.*, u.username
            FROM mybb_threads t
            LEFT JOIN mybb_users u ON (u.uid=t.uid)
            WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
            ORDER BY t.lastpost DESC 
            LIMIT 0, 6" // Change the last digit to how many recent post you want to be shown
        );

    $list = '';
    while($fetch = mysql_fetch_array($query))
    {
        $list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
		$poster = "<a href=\"forums/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Created by: {$poster}<br />";
		$list .= "<i>" .$fetch['replies']. " Replies</i>";
		$list .= "<i> , " .$fetch['views']. " Views</i><br />";
		$list .= " (<i>Last post by: " .$fetch['lastposter']. "</i>)<br /><hr width=\"50\"><br />";
	
    }
    //output
    echo $list;

?>

4. Change the amount of recent posts you want to have displayed

That's it!
Reply
#2
Looks Good. Let me have a try with this.

Thanks.
vBulletin/Wordpress/Magento/MyBB
Developer and Designer
Reply
#3
Awesome! Thanks a lot Smile
Reply
#4
Im getting this error ... I dont know why

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/fpshar5/public_html/home.php on line 2

Warning: require(www.fpsharepoints.com/board/global.php) [function.require]: failed to open stream: No such file or directory in /home/fpshar5/public_html/home.php on line 4

Warning: require(www.fpsharepoints.com/board/global.php) [function.require]: failed to open stream: No such file or directory in /home/fpshar5/public_html/home.php on line 4

Fatal error: require() [function.require]: Failed opening required 'www.fpsharepoints.com/board/global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/fpshar5/public_html/home.php on line 4
anyone will answer of my above question?
Reply
#5
My website have html pages, is there any way to add that code in those html ed pages ?
Reply
#6
Change them to PHP pages (Just changing the extension is enough), then put that code in where wanted.
Reply
#7
(2010-02-05, 07:28 PM)themulhaq Wrote: Im getting this error ... I dont know why

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/fpshar5/public_html/home.php on line 2

Warning: require(www.fpsharepoints.com/board/global.php) [function.require]: failed to open stream: No such file or directory in /home/fpshar5/public_html/home.php on line 4

Warning: require(www.fpsharepoints.com/board/global.php) [function.require]: failed to open stream: No such file or directory in /home/fpshar5/public_html/home.php on line 4

Fatal error: require() [function.require]: Failed opening required 'www.fpsharepoints.com/board/global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/fpshar5/public_html/home.php on line 4
anyone will answer of my above question?

Can you post the exact code you have used and also a link to your forums?
Reply
#8
When using the include function, you reference the file on the server, not the URL, so it would be
<?php
chdir("./board/"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
?>
Assuming that your forum is in your public_html/board folder
Reply
#9
Thanx this i was searching from many time. Good work.
[Image: quotationspage-banner.jpg]
Reply
#10
if you have the mybb global.php integrated already,there's no need to form complicated sql commands for getting proper results

usually, a query like this is sufficient:
$query = $db->simple_select('threads', '*', "fid='{$fid}' ORDER BY tid DESC

--no ad, just info--
if you want, you can look at my news page (click), the script which catches+formats+outputs the news is just 4kb large (90% of it html/css formatting of the post content).
it's even more lightweight than Tikitiki's site news plugin).
[Image: 350x19.jpg][Image: tstargermany.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)