Support » Plugins » [Plugin: Related Links by Category] Fix for duplicates

  • I ran across an error today – if multiple links/posts are assigned to multiple categories, both category’s links/posts will show – creating duplicates in the list of related links/posts. There might be an easier way to fix this, but this is what I did:

    In the plugin folder, open the file “related-links-by-category.php”

    Right before this code: (should be around line 27)
    foreach((get_the_category($post->ID)) as $category) {

    Paste the following code on a new line:
    $already_listed = array();

    Replace: (starting at line 34)

    foreach($catposts as $p) {
        if ($d <= $data['disp']) {
            if ($cur_id != $p->ID) {
                $related .= '<li><a href="'.get_bloginfo('home').'/?p='.$p->ID.'">'.$p->post_title.'</a></li>';
                $d++;
            }
        }
    }

    With the following code:

    foreach($catposts as $p) {
    	if ($d <= $data['disp']) {
    		if ($cur_id != $p->ID) {
    			if (!in_array($p->ID, $already_listed)) {
    				$already_listed[] = $p->ID;
    				$related .= '<li><a href="'.get_bloginfo('home').'/?p='.$p->ID.'">'.$p->post_title.'</a></li>';
    			}
    		}
    		$d++;
    	}
    
    }

    http://wordpress.org/extend/plugins/related-links-by-category/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Related Links by Category] Fix for duplicates’ is closed to new replies.