MyBB Community Forums

Full Version: Adding a "latest topics" panel to main website
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My forum is part of a football website. I would like to add a script to my main homepage that shows latest forum threads........


Is this possible?
You can modify this to do it.

Just change:
$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");

To:
$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "ORDER BY tid DESC LIMIT {$limit}");

And it will show the latest threads from all forums; bear in mind however that this does not take into account the permissions of guests, so if you have hidden forums it will also show posts from that.
In actual fact, if you just want a list, you can cut a lot of it out; the first part needs only be:
<?php

    $limit = 5;
    $forumpath = 'forum/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    chdir('../');
?>

And the second part needs only be this:
<?php
    
    $query = $db->simple_select(TABLE_PREFIX.'threads', '*', "ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {            
            $date = my_date($mybb->settings['dateformat'], $row['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row['dateline'], "", 1);
            
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row['uid']}\">{$row['username']}</a><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
Thanks I'll try that over the weekend