Home · sNews Development · [MOD] related articles

CMS-ZEN.COM

online web development :: art and design :: fun stuff
best budd
Home •sNews Development cms road trip PHP Scripts Photoshop Guides Css Guides Music and video clips Art Gallery Low Light Photography Impression Photography

sNews 17 released

NEW: sNewsCMS v1.7 Release has been made available for download.
Get it while it's hot!

[MOD] related articles

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.   <?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

moshe on 27.08.2008. 22:02

oo yea, this function serves me with projects im
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.

funlw65 on 26.08.2008. 23:37

Thank you Moshe,
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.

moshe on 26.08.2008. 20:24

that is an option as well :)
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

funlw65 on 26.08.2008. 18:22

Yes Moshe, is working but I put AND position = 1 inside retrieve_related, to exclude static pages from start.

moshe on 26.08.2008. 11:20

aahhhaa :)
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 :)

funlw65 on 26.08.2008. 00:44

Hi Moshe,
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?

moshe on 25.08.2008. 21:37

hey vasi,
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 :)

moshe on 24.08.2008. 20:29

hey vasi :)
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.

funlw65 on 24.08.2008. 15:50

Hi Moshe,
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

moshe on 09.08.2008. 23:11

as you said, there are only 5 queries haha
anyway i will fix my code with your fixes :)
thank you my friend

funlw65 on 09.08.2008. 15:12

And optimized this:
$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...

funlw65 on 09.08.2008. 15:04

I replaced this: echo "<ul class="relt">n"; With this: echo '<ul>'; But I think it must be: echo '<ul class="relt">';

moshe on 09.08.2008. 08:07

yes i think this right thing to do,
i forgot to remove them.

what line did you replace ?

funlw65 on 09.08.2008. 01:48

Hi Moshe!

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?

moshe on 09.06.2008. 21:38

you welcome my friend :)

funlw65 on 09.06.2008. 20:57

Definitely, is not Henrich's mod. his mod is based on category, your mod is based on related keywords... your is true related mode. I suspected this and is the reason why I asked about it. Thank you!

Write a comment

* = required field

:

:

:


1 + 8 =