Hey, here is the Related Article mod i use here on my site
this 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.
this 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>';
}
}
?>





on 2008-06-09 20:57:19
on 2008-06-09 21:38:24
on 2008-08-09 01:48:52
Today I installed your mod and is working great, thank you!
I removed those "n" chars and replaced one line of code. It was a translation mistake, or you wanted to check if someone is using your code?
on 2008-08-09 08:07:08
i forgot to remove them.
what line did you replace ?
on 2008-08-09 15:04:57
on 2008-08-09 15:12:03
$query = "SELECT * FROM ".db('prefix')."articles WHERE seftitle = '$art_id' AND published=1";
like this:
$query = "SELECT title,seftitle,category FROM ".db('prefix')."articles WHERE seftitle = '$art_id' AND published=1";
Of course, there are only 5 queries, so does not matter so much.
For my package I'm using "the control panel" made for @Henrich's mod...
on 2008-08-09 23:11:43
anyway i will fix my code with your fixes :)
thank you my friend
on 2008-08-24 15:50:39
I found another issue. If you let the function to look also in tags of static pages, somewhere you will have a link pointing to a yourdomain.com/home/your_homepage/ and this will be reported as identical content with yourdomain.com/
What you think?
Awesome day
on 2008-08-24 20:29:33
yes, you are right, i see the problem,
will have to consider the use of homeless uri mod ?
i dont use pages very much, i just use articles and cats.
will work on it :)
awesome evening my friend.
on 2008-08-25 21:37:49
after some testing with v16,
i think to my self,
Pages Do have home in the url,
thats the standart for pages is it ?
only if one has moded snews to work
without home for pages.
if i make a page, i can not access it without home as category.
what do you think ?
awesome evening my friend :)
on 2008-08-26 00:44:06
You get me wrong and is my fault because i did not explained well.
Look at this case:
------------------
On my blog, I have a static page defined as homepage. Normally, this page reside in home category. But, because is set as home page, you can access it with this link: yourdomain.com/ . Of course, you know you can access it also with yourdomain.com/home/yourpage/ . But only you know that :P not Google. And in your site, this link (yourdomain.com/home/yourpage/) does not exist. So, your page, because is home page, can be accessed only this way : yourdomain.com/ . And because of this, no problem with duplicate content.
Until your mod will display a link to this page (as related article) under an article with same tags as your homepage. And that link will be displayed as yourdomain.com/home/yourpage/ . In that moment, your "secret" link will be revealed to google bot and he will say: Gotcha! Duplicate content.
That is the reason I said your related articles mod must search for tags only in articles. And this is the case also with tag clouds of Equilni.
P.S.My category for static pages is 'page' :) but I have same problem when I set a static page as homepage... But I use a htaccess redirection :P
My friend, right?
on 2008-08-26 11:20:48
good morning vasi,
yes, i have an option for you to try :)
please change this query line:
$query = "SELECT * FROM ".db('prefix')."articles WHERE seftitle = '$art_id' AND published=1";
to:
$query = "SELECT * FROM ".db('prefix')."articles WHERE seftitle = '$art_id' AND published=1 AND position='1' AND category!='0'";
it exclude the home and static pages out of the results.
let me know if it what you pointed :)
on 2008-08-26 18:22:04
on 2008-08-26 20:24:44
i added it to the rel_articles function beacose
i use the retrieve_related function in different
places and or functions.
any way its do its job is good by me hehe :)
awesome evening my friend
on 2008-08-26 23:37:57
This mod is working great, I'm content. I saw that you "parametrized" also the name of tables... which made me think how you use it (excluding actual destination of function) :P !
Good evening to you too.
on 2008-08-27 22:02:47
working on, that includes more db tables, like subcat,
or multi sub categories, and if i remmber correctly,
i use it with snews 17, maybe a version of it, i cant remmber exactly hehe.