Page 1 of 1
Display Only Top Articles on a New Page
Posted: Tue May 18, 2010 8:19 pm
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.
Posted: Wed May 19, 2010 2:57 pm
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>» <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"> <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.
Thanks A Lot
Posted: Fri May 21, 2010 6:24 am
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