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.
and
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.
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 />';
}
}