MyBB Community Forums

Full Version: Displaying News on Homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Still not working, I'll just use the portal it came with , thanks for the help.
Right. Finally got it working via MSN. Here is the final code
<?php
$mysqlhost = "localhost";
$mysqlusername = "";
$mysqlpassword = "";
$mysqldbselect = "";
$prefix = "mybb_";
$fid = "2";

mysql_select_db($mysqldbselect, mysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%'") or die(mysql_error());
while($news = mysql_fetch_array($query))
{
echo "<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
Works beautifuly. Hmm wish there was a way to parse the bbcodes tho.
Works, many thanks! Smile

By the way, it also displays comments as an actual news post, I am going to see if I can fix that.
Suprisingly simple, just add...

WHERE p.replyto='0'

in the query. Then you only get the first post of each thread.
great idea
What about adding an avatar and such?
Right. Because of the requests and a few bugs found, here is the new code. It now has a forum path value, which means it can now use MyBB's config file and correct all link/image paths itself instead of having to edit multiple details yourself. You can also now limit how many to show (default is 10), it should also order the posts to show the latest ones (not random ones) and only show the starting posts, not replies. It also displays the poster's avatar and the time the thread was made in a new outputting style.
<?php
$forumpath = "./MyBBForum/"; // Path to your forums root directory (with trailing slash)
$fid = "2"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show

require $forumpath."inc/config.php";
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while($news = mysql_fetch_array($query))
{
	$date = gmdate("d-m-Y", $news['dateline']);
	$time = gmdate("h:i A", $news['dateline']);
	if($news['replies'] == "1")
	{
		$replytext = "reply";
	}
	else
	{
		$replytext = "replies";
	}
	if($news['avatar'] != "")
	{
		if(substr($news['avatar'], 0, 7) != "http://")
		{
			$url = $forumpath;
		}
		$avatarbit = "<td valign=\"top\" style=\"border: solid 1px #000000;\" rowspan=\"2\" width=\"150\" align=\"center\"><img src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" /></td>";
	}
	else
	{
		$avatarbit = "";
	}
	echo "<table cellpadding=\"7\" align=\"center\" style=\"border: solid 0px #000000;\" width=\"100%\">\n";
	echo "<tr>".$avatarbit."<td style=\"border: solid 1px #000000;\"\"><a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> ( ".$news['replies']." ".$replytext." ) <br />Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</td></tr>\n";
	echo "<tr><td style=\"border: solid 1px #000000;\"\">".$news['message']."</td></tr>\n";
	echo "</table><br />\n\n";
}
?>
I'm also in the middle of implementing BBcodes.
k776 Wrote:Right. Because of the requests and a few bugs found, here is the new code. It now has a forum path value, which means it can now use MyBB's config file and correct all link/image paths itself instead of having to edit multiple details yourself. You can also now limit how many to show (default is 10), it should also order the posts to show the latest ones (not random ones) and only show the starting posts, not replies. It also displays the poster's avatar and the time the thread was made in a new outputting style.
<?php
$forumpath = "./MyBBForum/"; // Path to your forums root directory (with trailing slash)
$fid = "2"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show

require $forumpath."inc/config.php";
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while($news = mysql_fetch_array($query))
{
	$date = gmdate("d-m-Y", $news['dateline']);
	$time = gmdate("h:i A", $news['dateline']);
	if($news['replies'] == "1")
	{
		$replytext = "reply";
	}
	else
	{
		$replytext = "replies";
	}
	if($news['avatar'] != "")
	{
		if(substr($news['avatar'], 0, 7) != "http://")
		{
			$url = $forumpath;
		}
		$avatarbit = "<td valign=\"top\" style=\"border: solid 1px #000000;\" rowspan=\"2\" width=\"150\" align=\"center\"><img src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" /></td>";
	}
	else
	{
		$avatarbit = "";
	}
	echo "<table cellpadding=\"7\" align=\"center\" style=\"border: solid 0px #000000;\" width=\"100%\">\n";
	echo "<tr>".$avatarbit."<td style=\"border: solid 1px #000000;\"\"><a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> ( ".$news['replies']." ".$replytext." ) <br />Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</td></tr>\n";
	echo "<tr><td style=\"border: solid 1px #000000;\"\">".$news['message']."</td></tr>\n";
	echo "</table><br />\n\n";
}
?>
I'm also in the middle of implementing BBcodes.

That is excellent. Thank's for your time. Sorry to annoy you via PM. Wink
Ok, we've modified your code to produce this:

http://dc.peerweb.org/ Big Grin

BBcode works. Haven't tried with the emoticons though.
Mind post or Pmin me that code...thats would rock. Big Grin
Pages: 1 2 3 4 5 6 7 8 9 10 11 12