• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

XenWord Forum List By Category

This entry is part of a series of entries "December 2016 - XenWord Development Log"
A very simple XenWord widget returns a list of forums based on a selection of the forum category. The first version had too many sql queries and so I rewrote the widget today. Other widgets are on my list to also fix.

The original version used two sql queries.

PHP:
/** @var $node_qry XenWordXFForums */
$node_qry = "
            SELECT node_id, title, display_in_list, node_type_id, parent_node_id FROM `xf_node`
            WHERE display_in_list = 1 AND node_type_id = 'Forum' AND parent_node_id = '$cat_id'
            ORDER BY `title` ASC
            LIMIT $number_of_forums
         ";

$nodes = XenForo_Application::get( 'db' )->fetchAll( $node_qry );

and

PHP:
/** @var $category_qry XenWordXFForums */
$category_qry = "
            SELECT node_id, title, display_in_list, node_type_id FROM xf_node
            WHERE display_in_list = 1 AND node_type_id = 'Category'
            ORDER BY `title` ASC
         ";

$categories = XenForo_Application::get( 'db' )->fetchAll( $category_qry );

Both of these queries were replaced with a cleaner use of XenForo models and methods. For example, it is much cleaner to use the following to return a list of categories.

PHP:
$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$nodes = $nodeModel->getAllNodes();

foreach ($nodes as $category ) {
  if ( $category['node_type_id'] == 'Category' ) {
    echo $category['title'] . '<br />';
  }
}
Next entry in series Featured Thread and Forum Widgets
Previous entry in series XenWord Dashboard

Blog entry information

Author
LPH
Views
1,489
Last update

More entries in Technology

More entries from LPH

Top