Member 3639
Active member
Here is a quick and simple way to get a list of the latest posts on your website
NOTE: This is not meant to be inside xenforo nor has it been designed in anyway to be used like that, it's for a quick last post block/latest news section on your actual website.
You will need this brilliant helper class by Shadab https://gist.github.com/722240
Simply download it and upload the file to "/library/GeekPoint/Symfony.php" (you will need to make the directory GeekPoint).
DEMO: http://www.gamingonlinux.com/posts.php
Put this at the very top of your page:
Put this where you want it to display.
Recent Changes:
05/12/2010 - Added ability to limit it to certain forums or just all of them.
05/12/2010 - Added double quote " filtering. - Edit done twice as it should replace with nothing not a -.
05/12/2010 - Added in config file includes so you don't need to edit any database stuff now.
06/12/2010 - Takes users permissions for viewing nodes into account as requested.
04/03/2011 - It now uses xenforo's database system to generate the query, should fix random errors.
20/08/2011 - Now uses xenforo's functions to construct the url (thanks shadab) and you can put in views and comment counts (replys).
NOTE: This is not meant to be inside xenforo nor has it been designed in anyway to be used like that, it's for a quick last post block/latest news section on your actual website.
You will need this brilliant helper class by Shadab https://gist.github.com/722240
Simply download it and upload the file to "/library/GeekPoint/Symfony.php" (you will need to make the directory GeekPoint).
DEMO: http://www.gamingonlinux.com/posts.php
Put this at the very top of your page:
PHP:
<?php
// get latest x forum posts from xenforo by liamdawe
// edit this to whatever folder your forum is in
$forum_url = 'chill/';
// change to the amount of posts you want displayed
$limit = 7;
// edit this to the directory your forum is in
$forum_directory = '/home/website/forum/';
$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` IN ($node_id_list) ORDER BY `last_post_date` DESC LIMIT {$limit}";
$topics_query = XenForo_Application::get('db')->fetchAll($sql_forum);
?>
Put this where you want it to display.
PHP:
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> Views: {$thread['view_count']}, Comments: {$thread['reply_count']}<br />
<br />";
}
Recent Changes:
05/12/2010 - Added ability to limit it to certain forums or just all of them.
05/12/2010 - Added double quote " filtering. - Edit done twice as it should replace with nothing not a -.
05/12/2010 - Added in config file includes so you don't need to edit any database stuff now.
06/12/2010 - Takes users permissions for viewing nodes into account as requested.
04/03/2011 - It now uses xenforo's database system to generate the query, should fix random errors.
20/08/2011 - Now uses xenforo's functions to construct the url (thanks shadab) and you can put in views and comment counts (replys).