1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Recent threads on a Xenforo Page

Discussion in 'XenForo Development Discussions' started by Brandon515, Jun 13, 2014.

  1. Brandon515

    Brandon515 Member

    Is there a way to display the newest 10 threads from a specific forum on a Xenforo page?

  2. Brogan

    Brogan XenForo Moderator Staff Member

    You would need to use the PHP callback function.
  3. Brandon515

    Brandon515 Member

    I tried that using the following code. The code works on an external php page, but throws errors when trying to use it on a page in Xenforo with a callback.

    I don't know all that much about php or callbacks.

    // get latest x forum posts from xenforo by liamdawe
    // edit this to whatever folder your forum is in
    $forum_url = '/';
    // change to the amount of posts you want displayed
    $limit = 10;
    $node = 9;
    // edit this to the directory your forum is in
    $forum_directory = '/home/mysite/public_html';
    $startTime = microtime(true);
    require($forum_directory. '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($forum_directory . '/library');
    GeekPoint_Symfony::initializeXenforo($forum_directory, $startTime);
    $nodeModel = XenForo_Model::create('XenForo_Model_Node');
    $nodes = $nodeModel->getViewableNodeList();
    $nodes_get = array_keys($nodes);
    $node_id_list = implode($nodes_get, ',');
    $sql_forum = "SELECT `title`, `thread_id`, `view_count`, `reply_count` FROM `xf_thread` WHERE `node_id` = $node  ORDER BY `last_post_date` DESC LIMIT {$limit}";
    $topics_query = XenForo_Application::get('db')->fetchAll($sql_forum);
    foreach ($topics_query as $thread)
        // The absolute thread url is constructed for you
        $threadUrl = XenForo_Link::buildPublicLink('full:threads', $thread);
        // Trimmed and properly escaped
        $threadTitle = XenForo_Template_Helper_Core::helperWordTrim($thread['title'], 50);
        echo "<a href=\"$threadUrl\">$threadTitle</a><br />
    <br />";
  4. Luis

    Luis Well-Known Member

  5. Nobita.Kun

    Nobita.Kun Well-Known Member

    callBack you must use static function.

Share This Page