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

Recent threads on external page. Problem

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

  1. Brandon515

    Brandon515 Member

    I have pieced together this code for my site from various threads around here. It displays the latest x number of threads from a forum on an external page. The one problem that I have is that the $threadUrl portion is not working.

    $forumUrl = 'http://www.mysite.com/'; //Forum URL, must end with slash
    $limit = 10; // Display this number of last posts
    $node = 9;
    $node2 = 2;
    $forumDirectory = realpath(__DIR__.'/'); // Full path to forum folder
    if(!$forumDirectory) {
        die('$forumDirectory is incorrect!');
    $startTime = microtime(true);
    require($forumDirectory. '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($forumDirectory . '/library');
    // Initializing application
    XenForo_Application::initialize($forumDirectory . '/library', $forumDirectory);
    XenForo_Application::set('page_start_time', $startTime);
    // Loading dependencies
    $xfDependencies = new XenForo_Dependencies_Public();
    // Initializing session
    // Reading viewable nodes list
    $nodeModel = XenForo_Model::create('XenForo_Model_Node');
    $viewableNodes = $nodeModel->getViewableNodeList();
    $nodeIds = array_keys($viewableNodes);
    $nodeIdsList = implode($nodeIds, ',');
    // Requesting last N viewable nodes
            $sql_forum = "SELECT * FROM `xf_thread` WHERE `node_id` = $node AND discussion_state='visible' ORDER BY `last_post_date` DESC LIMIT $limit";
            $lastThreads = XenForo_Application::get('db')->fetchAll($sql_forum);
    // Here you can insert the code you want
            // Displaying content
            foreach ($lastThreads as $thread) {
                $postModel = XenForo_Model::create('XenForo_Model_Post');
                $post = $postModel->getPostById($thread['first_post_id']);
                $bbCodeParser = new XenForo_BbCode_Parser(new XenForo_BbCode_Formatter_Wysiwyg);
                $bbCodeOptions = array(
                    'showSignature' => false,
                    'states' => array(
                        'viewAttachments' => false
                $threadTitle = $thread['title'];
                $threadDate =  date("d.m.y", $thread['post_date']);
                $author = $thread['username'];
                $threadUrl = XenForo_Application::get('options')->boardUrl . '/' . XenForo_Link::buildPublicLink('threads', $thread);
                $message = XenForo_ViewPublic_Helper_Message::getBbCodeWrapper($post, $bbCodeParser, $bbCodeOptions);
            echo "
                <a href=\"$theadUrl\">{$threadTitle}</a>
                <br /><br />
    Any help would be greatly appreciated.

  2. LPH

    LPH Well-Known Member

    Have you tried changing the last echo statement to single quotes so the $threadUrl is not evaluated?

    Notice your misspelling of $threadUrl?
  3. devRSG

    devRSG Member

    Thanks for the code!

    Fixing the typo LPH pointed out made everything work great.

Share This Page