Jump to content

Custom Icons


Atomic

Recommended Posts

We are going to be rapidly expanding our Knowledgebase with up to 500 articles and would like to make the layout a little more appealing. Is there a way to add custom icons? For example instead of a folder icons we'd like a WordPress icon. An email icon for Email articles etc.

 

Merry Christmas!

Link to comment
Share on other sites

quick example: create new PHP file in /includes/hooks/ directory, and add the following code in it:

 

<?php
add_hook("ClientAreaPage", 1, function($vars){

   $defaultIcon = "glyphicon glyphicon-folder-close";

   $kbIcons = array(
       1 => "glyphicon glyphicon-dashboard",
       4 => "glyphicon glyphicon-envelope",
       5 => "glyphicon glyphicon-download-alt"
   );

   foreach ($vars['kbcats'] as $index => $kb){
       if (isset($kbIcons[$kb['id']])){
           $vars['kbcats'][$index]['icon'] = $kbIcons[$kb['id']];
       }
       else {
           $vars['kbcats'][$index]['icon'] = $defaultIcon;
       }
   }

   return array("kbcats" => $vars['kbcats']);

});

you will see that at line #4 we define the default icon, this icon will be used with categories with no specific icon defined

 

then there is a list/array of category ids and their icons (Category ID => "Icon Class Name")

 

now we need to apply this changes to our template, open /templates/{Your-Template}/knowledgebase.tpl file, search for:

<span class="glyphicon glyphicon-folder-close"></span> {$kbcat.name}

 

and replace it with:

<span class="{$kbcat.icon}"></span> {$kbcat.name}

 

you may need to apply the same change in knowledgebasecat.tpl too

Link to comment
Share on other sites

Got it. But if I wanted to use something custom would I put the image path in the array? I highly doubt things like cPanel and Wordpress exist in Glyphicos or FontAwesome?

then you would need to change how this implementation work:

 

<?php
add_hook("ClientAreaPage", 1, function($vars){

   $defaultIcon = "<span class="glyphicon glyphicon-folder-close"></span>";

   $kbIcons = array(
       1 => "<img src='path/to/image.png' alt=''>",
       4 => "<span class="glyphicon glyphicon-envelope"></span>",
       5 => "<span class="glyphicon glyphicon-download-alt"></span>"
   );

   foreach ($vars['kbcats'] as $index => $kb){
       if (isset($kbIcons[$kb['id']])){
           $vars['kbcats'][$index]['icon'] = $kbIcons[$kb['id']];
       }
       else {
           $vars['kbcats'][$index]['icon'] = $defaultIcon;
       }
   }

   return array("kbcats" => $vars['kbcats']);

});

 

and in template files it will be:

{$kbcat.icon} {$kbcat.name}

Link to comment
Share on other sites

  • 2 weeks later...

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