3
i was looking into a way to show related articles. i just made this, and so far it seems to work correctly.
first i added a fulltext index to the "keywords" key
and put the following code in article.php
le="color: #000000"><?php if($article->keywords() !='') { $id = intval($_GET['storyid']); $db =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $query = "SELECT * FROM ".$db->prefix("stories")." WHERE MATCH (keywords) AGAINST ('$article->keywords') AND storyid != '$id' "; $result = mysql_query($query); $number = mysql_numrows($result); if (intval($number) != 0){ $xoopsTpl->assign('related_articles', "Related Articles"); while ($myrow = $db->fetchArray($result)){ $ret[$myrow['storyid']] = array( 'title'=>'<a href='.XOOPS_URL.'/modules/news/article.php?storyid='.$myrow['storyid']. '>'.$myts->htmlSpecialChars($myrow['title'] ).'</a>', 'date'=>formatTimestamp($myrow['published'], "s")); } } } $xoopsTpl->assign('ret', $ret);
then i placed the following code into "news_article.html"
le="color: #000000"><?php <table width='50%' cellspacing='0' cellpadding='1'> <tr> <th><{$related_articles}></th> </tr> <{foreach from=$ret item=storyid}> <tr class="<{cycle values="even,odd"}>"> <td> <{$storyid.title}> (<{$storyid.date}>)<br/> </td></tr><{/foreach}> </div><br/> </td> </tr> </table>
i haven't tested it on a large site as of yet, so i'm not sure how practical this solution is. If anyone has a better idea of how to accomplish this, i am interested in any input.