• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Show latest threads from XenForo in PHP

Puntocom

Well-known member
I have written this code, I post here hoping it to be useful for you:

PHP:
<?php
$hostname = "localhost";
$db_username = "USERNAME";
$db_password = "PASSWORD";

$link = mysql_connect($hostname, $db_username, $db_password) or die("Cannot connect to the database");
mysql_select_db("DATABASE") or die("Cannot select the database");

$q = "SELECT thread_id,title,username,first_post_id FROM xf_thread WHERE first_post_id > 0 ORDER BY thread_id DESC LIMIT 0,10";
$r = mysql_query($q);
echo "<ul>";
while ($row = mysql_fetch_array($r)) {
        $title = utf8_encode($row["title"]);
        $first_post_id = $row["first_post_id"];
        $limit = 26;
        if (strlen($title) > $limit)
           $title = substr($title, 0, strrpos(substr($title, 0, $limit), ' ')) . '...';
        $tid = $row["tid"];
        echo "<li><a target=\"blank\" href=\"http://www.YOURDOMAIN/posts/$first_post_id\">$title</a></li>";
}
echo "</ul>";
?>
 
You might want to add an additional where on the 'discussion_state' column. At the moment you're displaying all threads, regardless of their state. State can be one of visible, moderated or deleted.
Also, 'discussion_open' for open/close status.
There may also be other thread states which you may not want to show. At the moment your code displays them all.
 
With this script you also show the "hidden" threads from forums which are not public;) (for example adminboard, modboard, etc...)
 
Top Bottom