XF 2.2 Create in PHP a list of links to last topics


I'd like to code in PHP (outside XF) a list of the 10 last topics/threads (that are visible to visitors). I need the title and the thread ID in order to construct the full URL of each thread page. The URL is "sanitized" from the thread title.
In MySQL it's something like that
SELECT thread_id, title  FROM `xf_thread` WHERE `discussion_state`='visible' AND `discussion_open`=1 ORDER BY thread_id DESC LIMIT 0,10
I don't know how to call XF and make simple query like that.
Thanks for your help!
@Lukas W. made a very nice article about this. See if that helps you.

Using XenForo Code in other applications

Your finder query would be something like this:
$finder = \XF::finder('XF:Thread')
            ->where('discussion_state', 'visible')
            ->where('discussion_open', 1)
            ->order('thread_id', 'DESC')

$totalRows = $finder->total();
if($totalRows > 0)
    $rows = $finder->fetch();
    foreach($rows as $thread)
        echo '<h1>'.$thread->title.'</h1>';
        echo '<p>The thread ID is '.$thread->thread_id.'</p>';
        echo '<hr />';
Last edited:
Top Bottom