ecshop商品自定义url和标题

2011-11-06 23:55 来源:www.chinab4c.com 作者:ecshop专家

    ecshop商品自定义url和标题,这个是很多人都追求的一个功能。现在的ecshop的模板和路径千篇一律。为了让ecshop更加符合ecshop SEO优化。我们就不得不对ecshop url和标题进行自定义。我们可以通过对ecshop二次开发。来让ecshop商品地址实现自定义url

    1:修改数据库。增加字段

     alter table ecs_goods add column url varchar(40) default '';

   2:goods_info.htm

      <tr>
            <td class="label">自定义URL</td>
            <td><input type="text" name="url" value="{$goods.url}"  size="30" /></td>
          </tr>
    3:admin/goods.php修改以下程序

     $url = !empty($_POST['url']) ? trim($_POST['url']) : '';
    /* 入库 */
    if ($is_insert)
    {
        if ($code == '')
        {
            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id,url)" .
                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".
                    " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id','$url')";
        }
        else
        {
            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .
                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral,url)" .
                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".
                    " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral','$url')";
        }
    }

   4:伪静态规则。必须修改成以下

    RewriteRule ^([0-9a-zA-Z]+)-([0-9]+)(.*)\.html$  goods\.php\?id=$2 [QSA,L]
   5:build_uri函数商品重写修改成以下

     case 'goods':
            if (empty($gid))
            {
                return false;
            }
            else
            { 
    $url = $GLOBALS['db']->getOne("select url from ".$GLOBALS['ecs']->table('goods')." where goods_id = '$gid'");
    if($url){
      $uri = $rewrite ? $url."-".$gid : 'goods.php?id=' . $gid;
    }else{
      $uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid;
    }
              
            }

            break;

     来源:http://www.chinab4c.com