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

Best way to pull the entire forum recent posts to a wordpress widget offsite?

surfsup

Well-known member
#1
I have a wordpress site that is not on the same domain as my xenforo forum, what do I need in order to pull the most recent topics/posts and place it into a wordpress widget?
 

LPH

Well-known member
#2
PHP:
<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 -->
Adjust as you need.