随机获取相关联商品,减少网页相似度

2016-07-07 15:01 来源:www.chinab4c.com 作者:ecshop专家

大家在使用ECShop的时候, 有没有发现产品页被百度收录的很少? 有的网站被收录了不少商品页, 但由于内容相似度太高,site的时候没能显示。 为了提高百度收录的质量, 为了减少网页的相似度, 我们需要做标题的优化, 添加产品相关文章, 添加相关联的产品,添加与众不同的产品描述,如果把这些都做好,需要耗费很多时间很精力, 投入产出比不高。我们可以应用一些技巧, 比如随机获取相关联商品, 减少网页相似度。实现代码如下:

一. 在lib_goods.php添加get_random_linked_goods函数, 该函数实现随机获取某个分类的商品。

// 根据分类编号随机查找相关商品
  1. function get_random_linked_goods($cat_id)
  2. {
  3. // 获取分页页数
  4. $children = get_children($cat_id);
  5. $cat = $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') .
  6. " WHERE cat_id = '$cat_id'");// 获得分类的相关信息

  7. $where= "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';
  8. $count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE $where ");
  9. $size = isset($_CFG['related_goods_number'])&& intval($_CFG['related_goods_number']) > 0 ? intval($_CFG['related_goods_number']) : 4;
  10. $max_page = ($count> 0) ? ceil($count / $size) : 1;
  11. // 随机获取页数
  12. $page = rand(1,$max_page);

  13. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
  14. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  15. 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
  16. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' g ' .
  17. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  18. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  19. "WHERE g.cat_id = '$cat_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ";

  20. $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);

  21. $arr = array();
  22. while ($row = $GLOBALS['db']->fetchRow($res))
  23. {
  24. $arr[$row['goods_id']]['goods_id']= $row['goods_id'];
  25. $arr[$row['goods_id']]['goods_name']= $row['goods_name'];
  26. $arr[$row['goods_id']]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ?
  27. sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  28. $arr[$row['goods_id']]['goods_thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true);
  29. $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
  30. $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
  31. $arr[$row['goods_id']]['shop_price']= price_format($row['shop_price']);
  32. $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);

  33. if ($row['promote_price'] > 0)
  34. {
  35. $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  36. $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
  37. }
  38. else
  39. {
  40. $arr[$row['goods_id']]['promote_price'] = 0;
  41. }
  42. }

  43. return $arr;
  44. }
复制代码
二.在goods.php修改获取相关联商品的代码.
  1. // $linked_goods = get_linked_goods($goods_id);
  2. $linked_goods = get_random_linked_goods($goods['cat_id']);
复制代码
希望本文能给站长们一些启发, 把网站做得越来越好。 本文由www.deal188.com提供, 转载请保留网址。

回答:
相当不错的功能哈,支持ING……

还差点 那就是没有关联商品的时候应该随机调取

好感谢分享 这样对搜索引擎很友好 网站建设内链也不错了