Display Only Top Articles on a New Page

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
hefin
Posts: 8
Joined: Wed Mar 24, 2010 7:44 am

Display Only Top Articles on a New Page

Post by hefin »

I want to add a new page toparticles.php which should only contain the Top Viewed Articles from my site

Can you help me with the code.
Regards
Hefin Dsouza
http://hefin.in
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Haven't tested it, but this is the extracted code form the index.php file, save it as "top_articles.php" inside the main Hesk folder:

Code: Select all

<?php
$limit = 10;

define('IN_SCRIPT',1);
define('HESK_PATH','');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');

require(HESK_PATH . 'inc/database.inc.php');
hesk_dbConnect();
?>

<table border="0" width="100%">
<tr>
<td>&raquo; <i><?php echo $hesklang['popart']; ?></i></td>
<td style="text-align:right"><i><?php echo $hesklang['views']; ?></i></td>
</tr>
</table>
<?php
$sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` WHERE `type`=\'0\' ORDER BY `views` DESC, `art_order` ASC LIMIT '.hesk_dbEscape($limit);
$res = hesk_dbQuery($sql);

echo '<div align="center"><table border="0" cellspacing="1" cellpadding="3" width="100%">';
while ($article = hesk_dbFetchAssoc($res))
{
	echo '
	<tr>
	<td>
	<table border="0" width="100%" cellspacing="0" cellpadding="0">
	<tr>
	<td width="1" valign="top"><img src="img/article_text.png" width="16" height="16" border="0" alt="" style="vertical-align:middle" /></td>
	<td valign="top">&nbsp;<a href="knowledgebase.php?article='.$article['id'].'">'.$article['subject'].'</a></td>
	<td valign="top" style="text-align:right" width="200">'.$article['views'].'</td>
	</tr>
	</table>
	</td>
	</tr>';
}
echo '</table></div>';

/* Print footer */
require_once(HESK_PATH . 'inc/footer.inc.php');
exit();
?>
You should be able to change the number of top articles displayed by changing the setting fro $limit at the top of the script.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
hefin
Posts: 8
Joined: Wed Mar 24, 2010 7:44 am

Thanks A Lot

Post by hefin »

Thanks This Code Works perfectly.
I was planning to Develop a Facebook Application displaying the Top Articles from my FAQ and list it in the Application...Thanks a Lot for the Solution
Regards
Hefin Dsouza
http://hefin.in
Post Reply