[MOD] related articles
Hey, here is the Related Article mod i use here on my sitethis mod ported from mod by baker http://snewscms.com/forum/index.php?topic=4045.0
place this code in snews.php or external file,
then call the function on your index.php.
to form relation betwin articles:
use Keywords META Tag field, enter word you like.
<?php
//related arts
function retrieve_related($column, $table, $field, $value, $n, $id) {
$query = "SELECT $column FROM ".db('prefix')."$table WHERE ($value) AND id <> '$id' ORDER BY id DESC LIMIT $n ";
$result = mysql_query($query) or die(mysql_error().' <br />'.$query);
$retrieve = array();
while ($r = mysql_fetch_array($result)) {$retrieve[] = $r[$column];}
return $retrieve;
}
function rel_articles(){
$article = get_id('article');
if (!empty($article)) {
echo '<div class="box">';
$id = retrieve('id','articles','seftitle',$article);
$keywords = retrieve('keywords_meta','articles','seftitle',$article);
$kws = explode(",", $keywords);
$num_kw = count($kws);
if ($kws[0] != '') {
for ($i = 0; $i < $num_kw; $i++) {
$keywords = trim($kws[$i]);
$value .= " keywords_meta LIKE '%$keywords%' ";
if ($i < $num_kw-1) {
$value .= " OR ";
}
}
$get_art = retrieve_related('seftitle', 'articles', 'keywords_meta', $value,'5',$id);
$num_art = count($get_art);
echo "<ul class="relt">n";
echo "<li>Related Articles: </li>n";
if($num_art>0) {
for ($i = 0; $i < $num_art; $i++) {
$art_id = $get_art[$i];
$query = "SELECT * FROM ".db('prefix')."articles WHERE seftitle = '$art_id' AND published=1";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$home = s('home_sef');
$cat = $r['category'];
$categorySEF = retrieve('seftitle','categories','id',$cat);
$categorySEF = empty($categorySEF) ? $home : $categorySEF;
echo '<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a></li>'."n";
}
}
}
else {
echo l('no_relation');
}
echo '</ul>'."n";
}
else {
echo l('no_relation');
}
echo '</div>';
}
}
?>
09.06.2008. 19:03

Write a comment
* = required field