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
NO it dose not who the user namer of who posted it

news.php
<?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);
            $query3 = $db->simple_select(TABLE_PREFIX."users", "displaygroup", "uid = '{$row2['uid']}'");
$gid = $db->fetch_field($query, "displaygroup");

$query4 = $db->simple_select(TABLE_PREFIX."usergroups", "namestyle", "gid = '{$gid}'");
$username = $db->fetch_field($query, "namestyle");

$username = str_replace('{username}', $row2['username'], $username); 
            $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']}\">{$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.';
    }

?>
Ok, I've tested this this time; Replace:
$query3 = $db->simple_select(TABLE_PREFIX."users", "displaygroup", "uid = '{$row2['uid']}'");
$gid = $db->fetch_field($query, "displaygroup");
With:
$query3 = $db->simple_select(TABLE_PREFIX."users", "displaygroup", "uid = '{$row2['uid']}'");
$gid = $db->fetch_field($query3, "displaygroup");
if($gid == 0)
{
	$query3 = $db->simple_select(TABLE_PREFIX."users", "usergroup", "uid = '{$row2['uid']}'");
	$gid = $db->fetch_field($query3, "usergroup");
}

Also replace:
$query4 = $db->simple_select(TABLE_PREFIX."usergroups", "namestyle", "gid = '{$gid}'");
$username = $db->fetch_field($query, "namestyle");
With:
$query4 = $db->simple_select(TABLE_PREFIX."usergroups", "namestyle", "gid = '{$gid}'");
$username = $db->fetch_field($query4, "namestyle");
okay that worked thank you.
It dosnt seem to be working for me? It just comes up with the code where the thing should be. A few questions though. Firstly, with the path to mybb where it says "forum/" if my forum is thewheelforum should i put "thewheelforum/" or "/thewheelforum" secondly the bit that you are supose to put up the top, do you put that in the head, before the head or above the other bit in the body?

Thanks.
The head info has to go at the top of the PHP file after <?php

Your forum path should be "thewheelforum/"
So does it have to be a php file? Or can i do it using my plain html file? Or do i need to link it to a PHP file with the top script in it?
... no, it has to be in a file ending .php If it wasn't, that explains why you only saw the code.
I just wanted to mention that there's a plugin that does the same thing as this tutorial.
MrDoom Wrote:... no, it has to be in a file ending .php If it wasn't, that explains why you only saw the code.

So theres no way to do it in html? Thats a shame. Will it stuff things up if theres html in a PHP file?

I have also tryed the forum news plugin but it just comes up with this
"run_hooks("site_news_plugin_run"); ?>" Where the news should be?
No problem with using HTML in a PHP so long as you either put it inside echo statements for outside of the <?php tags. For example:
<?php
//The header stuff here
?>

Your HTML here

<?php
//Your news output here
?>

The rest of your HTML
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