MyBB Community Forums

Full Version: i want display latest thread on my main home page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
((Google Translation))

hello all

i want display latest "5" threads on my home page

forum dir --> "forum"

and i want make new file called " latest.php" to use it for display latest threads

I'm sorry because my English is bad


i used this code


<?php

   echo "<meta http-equiv='content-type' content='text/html; charset=utf-8' />";
  
//Connect to mybb db
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require '/global.php';

mysql_set_charset('utf8');

//query to get latest 5 threads
$query = mysql_query("SELECT * FROM mybb_threads t LEFT JOIN mybb_users u ON (u.uid=t.uid) ORDER BY t.lastpost DESC LIMIT 0, 5");

    $list = '';
    while($fetch = mysql_fetch_array($query))
    {
$list .= "  |  <strong><a href=\"forum/showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></strong>";

    }
    //output
    //echo $list;

//MyBB htmlspecialchars function
function htmlspecialchars_uni($message)
{
    $message = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $message); // Fix & but allow unicode
    $message = str_replace("<","<",$message);
    $message = str_replace(">",">",$message);
    $message = str_replace("\"","&quot;",$message);
    $message = str_replace("  ", "&nbsp;&nbsp;", $message);
    return $message;
}



echo "<marquee direction='right' scrollamount='3'>";
echo $list;
echo "</marquee></p> ";




?>


But show this messages

Fatal error: Cannot redeclare htmlspecialchars_uni() (previously declared in C:\wamp\www\latest.php:30) in C:\wamp\www\forum\inc\functions.php on line 4037


Please help me

:oops: deleted
you can show the latest thread using portal mod
You can try and use a sidebox plugin.
just remove the function declaration in your file as MyBB is loading its version automatically when you include global.php
when i change this

//Connect to mybb db
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require '/global.php';

to

@mysql_connect("localhost", "root", "") or die("Could not connect to MySQL");
@mysql_select_db("forum") or die("Could not connect to MySQL");

the file is working , But I want to use this code



chdir('forum');
define("IN_MYBB", 1);
require '/global.php';

and i don't know Where is the problem ?

please any one help me & fix this code or Give me another code to display the last 5 topics on external page
i gave you the solution.
(2011-12-17, 09:06 PM)pavemen Wrote: [ -> ]just remove the function declaration in your file as MyBB is loading its version automatically when you include global.php

(2011-12-18, 05:18 AM)pavemen Wrote: [ -> ]i gave you the solution.

please explain it , because i don't understand any thing Undecided
^ he suggested to not use function htmlspecialchars_uni($message)

simple example :
<?php
define("IN_MYBB", 1);
require_once("./global.php"); // Change this if needed
$tlimit = 5; // How many titles you want

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a><br />' . "\n";
}
?>

if Arabic threads are not shown correctly then you have to use required encoding ..
Finally succeeded

Thanks for all & special thanks to pavemen and ranjani

[Image: yMA97665.png]


<?php

define("IN_MYBB", 1);
require_once("forum/global.php"); // Change this if needed
$tlimit = 5; // How many titles you want


$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");

    $list = '';
    while($fetch = $db->fetch_array($query))
    {
        $list .= " | <strong><a href=\"forum/showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></strong>";
        /*
		$poster = "<a href=\"forum/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Created by: {$poster}  ";
        $list .= "<i>" .$fetch['replies']. " Replies</i>";
        $list .= "<i> , " .$fetch['views']. " Views</i>  ";
        $list .= " (<i>Last post by: " .$fetch['lastposter']. "</i>)<br /><hr width=\"50\"><br />";
        */
    }


//output

echo "<marquee direction='right' scrollamount='3'>";
echo $list;
echo "</marquee></p> ";

?>
Pages: 1 2