private static function LoadCategoryThreads($page = 1)
 {
     self::$total_category_threads = DB::WoW()->selectCell("SELECT COUNT(*) FROM `DBPREFIX_forum_threads` WHERE `cat_id` = %d", self::GetCategoryId());
     self::$category_threads = DB::WoW()->select("\n        SELECT DISTINCT\n          `a`.*,\n          `b`.`name` AS `author`,\n          `c`.`post_id`,\n          `c`.`blizzpost`,\n          `c`.`blizz_name`,\n          `c`.`message`,\n          `c`.`post_date`,\n          DATE_FORMAT(`c`.`post_date`, '%%d/%%c/%%Y') AS `formated_date`,\n          `c`.`author_ip`,\n          `c`.`edit_date`,\n          \n          `e`.`name` AS `last_post_author`,\n          `d`.`character_guid` AS `last_post_author_id`,\n          `d`.`post_id` AS `last_post_id`,\n          `d`.`blizzpost` AS `last_blizzpost`,\n          `d`.`blizz_name` AS `last_blizz_name`,\n          `d`.`message` AS `last_message`,\n          `d`.`post_date` AS `last_post_date`,\n          DATE_FORMAT(`d`.`post_date`, '%%d/%%c/%%Y') AS `last_formated_date`,\n          `d`.`author_ip` AS `last_author_ip`,\n          `d`.`edit_date` AS `last_edit_date`,\n          \n          IF(`a`.`flags` & %s, 2, (IF(`a`.`flags` & %s, 1, 0))) AS `flags_order`,\n          \n          IF(`f`.`read_date` >= `d`.`post_date`, 'read', '') AS `status`,\n          `f`.`page` AS `last_read_page`,\n          CEIL((SELECT COUNT(`thread_id`) FROM `DBPREFIX_forum_posts` WHERE `thread_id` = `a`.`thread_id`)/20 ) AS `pages`,\n          (SELECT COUNT(*)-1 FROM `DBPREFIX_forum_posts` WHERE `thread_id` = `a`.`thread_id`) AS `replies`,\n          (SELECT `post_id` FROM `DBPREFIX_forum_posts` WHERE `thread_id` = `a`.`thread_id` AND `blizzpost` = 1 ORDER BY `post_date` DESC LIMIT 1) AS  `first_blizz_post_id`\n        \n        FROM `DBPREFIX_forum_threads` AS `a`\n        LEFT JOIN `DBPREFIX_user_characters` AS `b` \n          ON `b`.`bn_id` = `a`.`bn_id` AND `b`.`guid` = `a`.`character_guid`\n        LEFT JOIN `DBPREFIX_forum_posts` AS `c`\n          ON `c`.`thread_id` = `a`.`thread_id` AND `c`.`post_id` = (SELECT `post_id` FROM `DBPREFIX_forum_posts` WHERE `thread_id` = `a`.`thread_id` ORDER BY `post_date` ASC LIMIT 1)\n        LEFT JOIN `DBPREFIX_forum_posts` AS `d`\n          ON `d`.`thread_id` = `a`.`thread_id` AND `d`.`post_id` = (SELECT `post_id` FROM `DBPREFIX_forum_posts` WHERE `thread_id` = `a`.`thread_id` ORDER BY `post_date` DESC LIMIT 1)\n        LEFT JOIN `DBPREFIX_user_characters` AS `e` \n          ON `e`.`bn_id` = `d`.`bn_id` AND `e`.`guid` = `d`.`character_guid`\n        LEFT JOIN `DBPREFIX_forum_threads_reads` AS `f` \n          ON `f`.`bn_id` = %d AND `f`.`thread_id` = `a`.`thread_id`\n        WHERE `a`.`cat_id` = %d\n        ORDER BY `flags_order` DESC, `c`.`post_date` DESC\n        LIMIT %s%s", THREAD_FLAG_FEATURED, THREAD_FLAG_PINNED, WoW_Account::GetUserID(), self::GetCategoryId(), $page > 0 ? ($page - 1) * 20 . ', ' : null, '20');
     self::HandleCategoryThreads();
 }