MyBB Community Forums

Full Version: [Need Help]Latest Threads on HomePage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

How can I show one [Only The Newest] Thread On My homepage

my homepage is html file the forum is on /forum/


Thanks !!!
you can't do that on a normal html page. I advice you to copy the whole code into a phpfile and add this piece of code where you want to show the latest thread.
<?php
require "forum/global.php";
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."threads WHERE 1=1 ORDER BY dateline DESC LIMIT 0,1");
$thread = mysql_fetch_array($query);
echo '<a href="forum/showthread.php?tid='.$thread['tid'].'">'.$thread['subject'].'</a>';
?>

The part after echo is a normal html link. You can always change the html a bit, but I advice you to keep this link intact.
Thank You !!!
Working Great
Please replace the query with the following so that drafts are not shown:
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."threads WHERE visible = '1' ORDER BY dateline DESC LIMIT 0,1");
Hmm, but this doesnt seem to work for me. My forum is on / but my site is on /kb and it won't link correctly. Can this be fixed?
Replace the line
echo '<a href="forum/showthread.php?tid='.$thread['tid'].'">'.$thread['subject'].'</a>';
with
echo '<a href="http://www.your_url.tld/showthread.php?tid='.$thread['tid'].'">'.$thread['subject'].'</a>';
Replace http://www.your_url.tld/showthread.php with the real URL to your forums.
hello everybody,
I hope you are having a great new year start.
The above code is not working in my case.
it says

Direct initialization of this file is not allowed.

Please make sure IN_MYBB is defined.

what should I do ?