Mortfiles Posted July 10, 2015 Share Posted July 10, 2015 I am rebuilding the knowledgebase and I need a hand in how to output the latest (or most popular) 5 items from each category in the overview in knowledgebase.tpl 0 Quote Link to comment Share on other sites More sharing options...
Mortfiles Posted July 13, 2015 Author Share Posted July 13, 2015 Seriously? No one have a clue? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted July 13, 2015 Share Posted July 13, 2015 using Action Hooks you can query the required information from DB and pass it to your template then display it there here is your Action Hook: <?php use Illuminate\Database\Capsule\Manager as Capsule; function hook_getLatestFiveKBPerCategory($vars){ $categoryID = intval($_GET['catid']); # Latest Articles For Specific Category if ($categoryID!=0){ $getLatestArticles = Capsule::table('tblknowledgebaselinks') ->join('tblknowledgebase', 'tblknowledgebaselinks.articleid', '=', 'tblknowledgebase.id') ->where('tblknowledgebaselinks.categoryid', '=', $categoryID) ->orderBy('id', 'desc') ->take(5) ->get(); } else { $getLatestArticles = Capsule::table('tblknowledgebase') ->orderBy('id', 'desc') ->take(5) ->get(); } $encodedata = json_encode($getLatestArticles); $decodedata = json_decode($encodedata, true); return array("latestkb" => $decodedata); } add_hook("ClientAreaPage", 1, "hook_getLatestFiveKBPerCategory"); and in your TPL file you can print this information like the following: {foreach $latestkb as $article} {$article.title} {$article.views} {/foreach} - - - Updated - - - will work only for WHMCS v6+ 1 Quote Link to comment Share on other sites More sharing options...
Mortfiles Posted July 13, 2015 Author Share Posted July 13, 2015 Awesome! Now lets just figure out where the action hook actually go... I just create a new file in /includes/hooks/ according to the documentation (what name?) or in the modules section /modules/addons/hooks.php? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted July 13, 2015 Share Posted July 13, 2015 create new file inside /includes/hooks/ directory it's name can be anything like (latestkbarticles.php), the copy and paste this code to it. - - - Updated - - - if you are inside knowledge base category it will get you latest 5 articles added to that category, otherwise it will get latest 5 articles added 0 Quote Link to comment Share on other sites More sharing options...
Mortfiles Posted July 13, 2015 Author Share Posted July 13, 2015 Ah. And I would like to have it on the front page so it pick the last 5 for each category... Like so:http://www.microhost.se/knowledgebase.php Is that possible? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.