imaginit Posted December 13, 2008 Share Posted December 13, 2008 I want to display the most viewed knowledge base articles, and in the future maybe other items from the internal sections of the site on custom pages. This does not seem to be easily possible. The variable $kbmostviews is not available on any page but knowledgebase.php. I am not sure if I can use some built in function to get that variable on an additional page or if I have to build a custom smarty plugin that connects to the DB and such. Any insight would be appreciated. Thanks! 0 Quote Link to comment Share on other sites More sharing options...
imaginit Posted December 16, 2008 Author Share Posted December 16, 2008 I figured this out and wrote a really simple function to populate the proper variable and assign it to a smarty variable. This function will only work within the WHMCS system. Meaning you have to create a page as outlined at the below link and then use thise code in that. I did this to create my own custom home page that can display knowledge base article information on it. http://wiki.whmcs.com/Creating_Pages function list_kb_most_viewed($numarticles) { $kbmostviews = mysql_query("SELECT *, replace(replace(replace(replace(replace(replace(title,' ', '_'),'&','and'),'&','and'),';', ''),'/', 'or'),'\\\\', '') as urlfriendlytitle FROM tblknowledgebase ORDER BY views DESC LIMIT 0,$numarticles"); while ($row = mysql_fetch_assoc($kbmostviews)) $data[] = $row; return $data; } 0 Quote Link to comment Share on other sites More sharing options...
Maexx Posted December 26, 2008 Share Posted December 26, 2008 To show most viewed knowledgebase articles to an external page you should use this part of code. Thanks to netzone <?php // Connects to your Database mysql_connect("host", "user", "pass") or die(mysql_error()); // host: your host or IP, user: database user, password: your database user's password mysql_select_db("database") or die(mysql_error());// database of whmcs $x=1; // truncate the text to only 80 chars, add ... to the end function truncat($text) { $text = substr($text,0,80); $text = substr($text,0,strrpos($text,' ')); $text = $text." ... "; return $text; } // format the date to mm/dd/yyyy function formatdat($date) { $year = substr ($date, 0, 4); $month = substr ($date, 5, 2); $day = substr ($date, 8, 2); return $day.'/'.$month.'/'.$year; } // limit the number of announcements to return. Default is 15 $limit = 15; $result = mysql_query("SELECT * FROM tblknowledgebase ORDER BY views DESC LIMIT ".$limit); while($data = mysql_fetch_array ($result)) { $id = $data['id']; $date = $data['date']; $title = truncat($data['title']); $date = formatdat($date); echo'<div><a href="http://www.yourdomain.com/knowledgebase.php?action=displayarticle&id='.$id.'" class="tekst"><b>'.$title.'</b></a><br> '; echo'</div>'; } ?> 0 Quote Link to comment Share on other sites More sharing options...
neocorps Posted June 10, 2010 Share Posted June 10, 2010 I have a question, How about when you search something in the Knowledgebase.php, it gives you something like this on the url : knowledgebase.php?action=search Does this mean that the $kbmostviews is available on that page?, because I've been trying to use it and it doesn't appear to work. Maybe I'm doing something wrong but I'd like to know if the variable is available or not. 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.