2017-07-10, 12:41 AM
Definitely know questions on this topic have been asked haha! However,
I'm trying to use this php code which can show latest posts on your website. Only I'm trying to use it as a news system.
So like I said, I'd like to use this as a news system. First am I suppose to edit the ['tid'] to make the link actually work? Because I'm getting a URL does not exist.Secondly, I'd like to show the content of the actual thread. Third I just would like to show the content from one category so do I need to add another code in the php to do this. Also is there a better code to use for what I want to get done?
I'm trying to use this php code which can show latest posts on your website. Only I'm trying to use it as a news system.
<?php
chdir("forums"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
global $mybb, $db, $cache, $lang, $plugins; // Trim this list of global vars, if you want to.
?>
<?php
$query = $db->query("
SELECT t.*, u.username
FROM mybb_threads t
LEFT JOIN mybb_users u ON (u.uid=t.uid)
WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.lastpost DESC
LIMIT 0, 6" // Change the last digit to how many recent post you want to be shown
);
$list = '';
while($fetch = $db->fetch_array($query))
{
$list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
$poster = "<a href=\"forums/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
$list .= "Created by: {$poster}<br />";
$list .= "<i>" .$fetch['replies']. " Replies</i>";
$list .= "<i> , " .$fetch['views']. " Views</i><br />";
$list .= " (<i>Last post by: " .$fetch['lastposter']. "</i>)<br /><hr width=\"50\"><br />";
}
//output
echo $list;
?>
So like I said, I'd like to use this as a news system. First am I suppose to edit the ['tid'] to make the link actually work? Because I'm getting a URL does not exist.Secondly, I'd like to show the content of the actual thread. Third I just would like to show the content from one category so do I need to add another code in the php to do this. Also is there a better code to use for what I want to get done?