MyBB Community Forums

Full Version: Displaying News on your 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 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Very nice, I'll try this out soon. Thanks!
DCR Wrote:Hmm Thanks, but it did not work..
It should have done. Here's what each option in that array does:
// * @param array Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username.

What does it output actually output?
It outputs the HTML codes.

By the way, I;m using the multipage one if it has anything to do, but I doubt it since it has the same array.
Oops, my bad:

Change it to:
$options = array(
			'allow_html' => 'yes', 
			'filter_badwords' => 'yes', 
			'allow_mycode' => 'yes', 
			'allow_smilies' => 'yes', 
			'nl2br' => 'yes', 
			'me_username' => 'yes'
			);
$message = $parser->parse_message($row2['message'], $options);
Ah perfect. Thank Wink
i am getting errors

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc31956-OAMT/www/index.php:11) in /mounted-storage/home43a/sub006/sc31956-OAMT/www/forum/inc/functions.php on line 1133

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc31956-OAMT/www/index.php:11) in /mounted-storage/home43a/sub006/sc31956-OAMT/www/forum/inc/functions.php on line 1133

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc31956-OAMT/www/index.php:11) in /mounted-storage/home43a/sub006/sc31956-OAMT/www/forum/inc/functions.php on line 1133

you can see it at http://devtech.org
This part should be before anything which outputs to the screen, is it?
$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('../');

It doesn't matter where the rest of the code goes so long as that code is put before any output.
okay this is what i done

news.php
<?php

    $fid = 3;
    $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('../'); 
    
    $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', '*', "tid='{$row['tid']}' LIMIT 1");
            $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 i put this on my index.php

<?php include("news.php"); ?>

and i am getting that error
Probably because the include is placed after the headers have ended. (Content has started).

If you want to do that; make two files. Make a file called "newsheader.php" and include it after the <?php bit at the very top of the page you want to include it on. Fill the file with the following:
<?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('../');

?>
If your page has HTML before it's PHP (i.e. Content before the <?php tag) then place this at the very top of the file like this:
<?php include('newsheader.php'); ?>

Now edit your current "news.php" so that it has the remaining code and include it from where your currently are:
<?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', '*', "tid='{$row['tid']}' LIMIT 1");
            $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.';
    }

?>
nop still did not work http://devtech.org/ see it just put the error at the top of the page now.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33