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
Maybe it's the way I made it wrong,
I've got an index page (index.htm) and I've got a inline frame into it whats forum.php and that are the latest forum topics.
K I fixed the main problem but now I got this:

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/owiosa1.nl/subdomains/fearless/httpdocs/asd.php:10) in /usr/local/psa/home/vhosts/owiosa1.nl/subdomains/fearless/httpdocs/forum/inc/functions.php on line 802
It's all fixed now thx a lot guys.
Everything worked fine until I deleted a child forum (News)
Now my page isn't showing off all the latest posts it inly was by News

What's wrong with my code?
BTW I deleted password and etc in the code showinh down here.

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

$message['post'] = postify($message['post'], $allowhtml="yes", $allowmycode="yes", $allowsmilies="yes", $allowimgcode="yes", $archive=0);

$query = $db->query("
	SELECT t.tid,t.subject
	FROM mybb_threads t	LEFT JOIN mybb_posts p ON (t.tid = p.tid)
	WHERE t.fid=2
	AND t.visible=1
	AND t.closed NOT LIKE 'moved|%'
	ORDER BY t.dateline DESC
	LIMIT $limit")
or die($db->error());
while($news = $db->fetch_array($query))
{
echo "<div style=\"padding:3px\"><a href=\"./forum/showthread.php?tid=".$news['tid']."\" target=\"_blank\">".$news['subject']."</a></div>";
}
K I fixed that just remove WHERE t.fid=2. But now it also shows the topics in a password locked forum, how to fix that

It only has got to show: fid: 1 3 5 6 7 8 9 10
mysql_select_db($mysqldbselect, mysql_connect($mysqlhost, $mysqlusername, $mysqlpassword));

$message['post'] = postify($message['post'], $allowhtml="yes", $allowmycode="yes", $allowsmilies="yes", $allowimgcode="yes", $archive=0);

$query = $db->query("
	SELECT t.tid,t.subject
	FROM mybb_threads t	LEFT JOIN mybb_posts p ON (t.tid = p.tid)
	AND t.visible=1
	AND t.closed NOT LIKE 'moved|%'
	AND password = ''
	ORDER BY t.dateline DESC
	LIMIT $limit")
or die($db->error());
while($news = $db->fetch_array($query))
{
echo "<div style=\"padding:3px\"><a href=\"./forum/showthread.php?tid=".$news['tid']."\" target=\"_blank\">".$news['subject']."</a></div>";
}
That should filter out private forums (the ones with passwords), which is what you want.
OK, what I've done now, is use the PHP from this thread to show news posts on my homepage, and then made a Joomla mod with it. You can see it here: http://www.generalemu.be. Now, I'm not sure how to fix the parsing of the bbcode to have it show the quotes and lists correctly, as they aren't being parsed. Also, is there any way to have attachments show on the homepage (even thumbnails if it's attached images)? And wondering how I can insert a line to separate the posts that are being shown. Any help with this would be greatly appreciated. Here's the PHP I have so far, which has most of it working.
<?php 
$forumpath = "./forums/"; // Path to your forums root directory (with trailing slash)
$fid = "5"; // The forum ID to pull the annoucements from
$limit = "30"; // The amount of annoucements to show
require $forumpath."inc/config.php";

function bb_code(&$string){
    $pattern = array(
        //[ul]
        '#\[list\](.*?)\[\/list\]#si',
        //[*]
        '#\[\*\](.*?)(\r\n|\r|\n|<br>|<br />|<br/>)#si',
        //[url]
        '#\[url\](.*?)\[\/(url)\]#si',
        //[url=XXX]
        '#\[url=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/url\]#si',       
        //[i],[u]
        '#\[u\](.*?)\[/u\]#si',
        '#\[i\](.*?)\[/i\]#si',
        //[b]
        '#\[b\](.*?)\[/b\]#si',
        //[img]
        '#\[img\](.*?)\[\/img\]#si',
        // font size
        '#\[size=(&quot;|"|\'|)([0-9\+\-]+)\\1\](.*?)\[\/size\]#si',        '#(\r|\n|\r\n)#si');

    $replacement = array(
        //ul
        "\t\t<ul>$1</ul>\r\n",
        //li
        "\t\t\t<li>$1</li>\r\n",
        //a
        '<a href="$1">$1</a>',
        //a
        '<a href="$2">$3</a>',
        //i, u
        '<u>$1</u>',
        '<em>$1</em>',
        //b
        '<strong>$1</strong>',
        //img                             
        '<img src="$1" alt="User Posted Image" />',
        //size                  
        '<font size="\2">\3</font>',        "<br />");
    $string = preg_replace ($pattern, $replacement, stripslashes($string) );    $string = str_replace ('<br /><br />', "</p>\r\n\t\t<p>", $string);
}
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 ("jS F Y", $news['dateline']);
    $time = gmdate ("h:i A", $news['dateline']);

    //Parse BBCode
    bb_code($news['message']);

    if($news['replies'] == "1"){
        $replytext = "reply";
    } else {
        $replytext = "replies";
    }

    if($news['avatar'] != ""){
        if(substr($news['avatar'], 0, 7) != "http://")
        {
            $url = $forumpath;
        }
        $avatarbit = "<img style='float:left; margin:10px;'src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" />\r\n\t\t";
    } else {
        $avatarbit = "";
    }

    echo "\t<div class=\"news\">\r\n\t\t";
    echo "<div class='details'>(<a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['replies']." ".$replytext." </a>) | Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</div>\r\n\t\t";
    echo "<h2>".$news['subject']."</h2>\r\n\t\t";
    echo $avatarbit."<p>".$news['message']."</p>\r\n\t\t<div style=\"clear:both;\"></div>\r\n\t";
    echo "</div>\r\n";
}
?>
Hi.
I am trying the script but I am getting the following error::
Quote:Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource
Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Warning: mysql_query(): A link to the server could not be established

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I know the line I having a problem is this one:

Quote:mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

What i am doing is filling in mysql info. like so.

Quote:mysql_select_db($config['bodyforums'], mysql_connect($config['mysql91.secureserver.net'], ect.

Am I doing it right?
You need to enter the path to your board. For that purpose you have to change the following line:
$forumpath = "./forums/"; // Path to your forums root directory (with trailing slash)
Then there's no need to edit anything else as the script gets the database connection details from inc/config.inc.php.
Go it! Thanks. Works great.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12