<div class="forum_posts">    
    
    <h3>The following posts are from our community</h3>
    
    <?php
    
    /* Script to pull the latest posts from the XF Forum */    
        
    $db = XenForo_Application::getDb();
    
    if (!$db) {
    
        die('This script did not connect to the database' . mysql_error());
    
    }
    
    $thread_qry = "
            SELECT * FROM `xf_thread`
            ORDER BY `last_post_date` DESC
            LIMIT 5
     
    ";
    
    $threads = XenForo_Application::get('db')->fetchAll($thread_qry);
     
    foreach ($threads AS $thread)
    {
            $latestthreads[$thread['thread_id']] = array(
            'id' => $thread['thread_id'],
            'title' => $thread['title'],
            'url' => XenForo_Link::buildPublicLink('canonical:threads', $thread),
            'replycount' => $thread['reply_count'],
            'dateline' => $thread['post_date'],
            'viewcount' => $thread['view_count']
            );
     
            echo ("<div class='entry-meta'><a href='/community/" . XenForo_Link::buildPublicLink('threads', $thread) .    "' >" . $thread['title'] . "</a> Viewed: "  .$thread['view_count'] .       "<br /></div>"); // Echo the title with a link. 
     
    }
    
    ?>
</div><!-- Latest Forum Posts -->