Jump to content

Knowledgebase - show latest 5 items in each category?


Mortfiles

Recommended Posts

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+

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated