MyBB Community Forums

Full Version: RE: Include recent forum posts in homepage.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Can someone please tell me how to include like 5 recent topics in which posts have been made from forum in main homepage, i have a website and a mybb forum, and i wan't the last 5 updated topics to be shown in main page.

Also i would like to know how to include topic's contents from 1 category, i want to use it like news system, like in News category people posts different news topics, and they apear on first page, the topic title and content.
There's plenty of plugins that you can download.

Here's one I use:
http://mods.mybboard.net/view/prostats

Here's one I have un-installed:
http://mods.mybboard.net/view/advanced-s...mybb-1-4-x
That is for forum, like for forum index/portal, but i need the last posts/news to show on a seperate website.
Try this one

<?php

/** Config **/

$dbhost = "localhost";

$dbuser = "";

$dbpassword = "";

$dbdatabase = "";

$prefix = "mybb_"; //Databaseprefix



$url = "http://"; // URL to the board

$viewable_forums = ""; //viewable forums - seperate with coma , (for examble "2,11")

$limit = "5"; // How many topics we want to see?

$length = "15"; // length of the subject (0 ist full length)

/** End of config **/



// We connect to the database

$db = mysql_connect($dbhost,$dbuser,$dbpassword) or die ("Verbindung fehlgeschlagen");

mysql_select_db($dbdatabase,$db);

$viewable_forums = str_replace(","," OR fid=",$viewable_forums);



echo "<ul>";

// username= author // replies = answers

$query = mysql_query ("SELECT subject,tid,replies,fid FROM ".$prefix."threads WHERE visible='1' AND fid=".$viewable_forums." ORDER BY tid DESC LIMIT 0,".$limit."");

while ($newest_threads = mysql_fetch_array($query))

{

    if ($length != 0)

    {

        if (strlen($newest_threads['subject']) > $length)

        {

            $newest_threads['subject'] = substr($newest_threads['subject'],0,$length) . "...";

        }

    }

    echo "<li>".$newest_threads['subject']." (".$newest_threads['replies']." ".($newest_threads['replies']!="1"?"Replies":"Reply")."

<a href=\"".$url."/forum/showthread.php?tid=".$newest_threads['tid']."\" target=\"_blank\">Go to Topic</a>)</li>";

}

echo "</ul>";

?>

Edit:the script is for an older version but feel free to test and its not about posts but topic Wink
One more thing, how to make it like be utf-8 so it would get letters like āšģī from the title, because its showing like "Svei?i k? iet" something like that.
All your php files of the website(if they are) must be saved as UTF8 Without BOM and the charset should be utf-8 as well!
Maybe even the website's mysql tables(if it has such)
All other letters like that work on website, im using this news script to get topic titles and content to news page http://mods.mybboard.net/view/site-news-...ned-for-14 and those letters work in there too, the code you gave me is the only part that has the ? symbols instead of the long letters.
The problem probably comes from these

        if (strlen($newest_threads['subject']) > $length)

        {

            $newest_threads['subject'] = substr($newest_threads['subject'],0,$length) . "...";
Read about multibyte strings
not realy that part makes the topic titles shorter if they are to long, i deleted that line and i still get ?'s
got if fixed.

mysql_connect("","","");
mysql_query("SET NAMES utf8");
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'fpshar5'@'localhost' (using password: NO) in /home/fpshar5/public_html/home.php on line 129
Verbindung fehlgeschlagen

I'm having this error Sad
Pages: 1 2