2007-08-14, 06:08 PM
I'm sure there was a tutorial on this before but it seems to have vanished... oh well.
This tutorial will enable you to show posts from a specific forum in your MyBB forum on your website's homepage.
This code should be placed at the top of your page (before any output):
This code should then be placed where you would like the news to be shown:
Then you need to replace:
- The 2 in "$fid = 2" with the fid of the forum you want to show the posts from
- The 5 in "$limit = 5" with whatever you want your limit to be.
- The 'forum/' in chdir('forum/') to your forum path relative to the page this is being called from.
- The '../' in chdir('../') to the path back from your forum to the page this is being called from.
You will also need to change the code in the echo() statements to reflect how you want the news to be displayed on your site.
UPDATE - PLEASE READ
This tutorial will enable you to show posts from a specific forum in your MyBB forum on your website's homepage.
This code should be placed at the top of your page (before any output):
<?php
$fid = 2;
$limit = 5;
$forumpath = 'forum/';
chdir($forumpath);
define("IN_MYBB", 1);
require('./global.php');
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
chdir('../');
?>
This code should then be placed where you would like the news to be shown:
<?php
$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
if($db->num_rows($query) > 0)
{
while($row = $db->fetch_array($query))
{
$query2 = $db->simple_select(TABLE_PREFIX.'posts', '*', "pid='{$row['firstpost']}'");
$row2 = $db->fetch_array($query2);
$date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
$time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);
$options = array(
'allow_html' => 'no',
'filter_badwords' => 'yes',
'allow_mycode' => 'yes',
'allow_smilies' => 'yes',
'nl2br' => 'yes',
'me_username' => 'yes'
);
$message = $parser->parse_message($row2['message'], $options);
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> -
Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
echo("{$message}<br /><br />");
echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
}
}
else
{
echo 'Nothing to display.';
}
?>
Then you need to replace:
- The 2 in "$fid = 2" with the fid of the forum you want to show the posts from
- The 5 in "$limit = 5" with whatever you want your limit to be.
- The 'forum/' in chdir('forum/') to your forum path relative to the page this is being called from.
- The '../' in chdir('../') to the path back from your forum to the page this is being called from.
You will also need to change the code in the echo() statements to reflect how you want the news to be displayed on your site.
UPDATE - PLEASE READ