优化ecshop自动生成类目页Keywords、Desciption Meta
2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家
ECshop支撑对于每个新建的类目自定义Keywords、Description Meta信息,好处就不用说了,协助SEO或许让阅读者了解这是啥页面,但如果有几百个类目的时分,人工去写这些类目又有点累人(咱不干体力劳动的 活),花了点时刻,写了个主动生成Keywords、Description的PHP脚本,支撑四级分类,原理是子类目包括父亲类目、爷爷类目。。。到顶 级类目名作为关键字,然后一句描述的话,包括这些类目的称号。我们能够依据自个需求简略的修改。
用法,在你的后台类目,默许是Admin里面创立一个新的PHP文件,文件名自定义,将下面的代码仿制进入就能够了,需求生成的时分,访问一下这个文件就主动生成了。
<?php
set_time_limit(600);
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$sql_1 = "SELECT cat_id,cat_name FROM " .$ecs->table('category'). " where parent_id = 0 ORDER BY cat_id asc";
$res_1 = $db->query($sql_1);
//一级类目循环
while ($row_1 = $db->fetchRow($res_1))
{
//取得一级类目子类目
$sql_2 = "SELECT cat_id,cat_name FROM " .$ecs->table('category'). " where parent_id = ". $row_1['cat_id'] ." ORDER BY cat_id asc";
$res_2 = $db->query($sql_2);
print "*** 一级分类:" . $row_1['cat_name'] ."<br>";
//一级类目子类目循环
$keyword_1 = '';
$c2 = 0;
while ($row_2 = $db->fetchRow($res_2))
{
$c2 = $c2 + 1;
if ($c2 < 7)
{
//生成一级类目的关键词和描述,取前X个
$keyword_1 = $keyword_1 . replace_cat_name($row_2['cat_name']) . ", ";
}
//=====================================================================
//取得二级类目子类目
$sql_3 = "SELECT cat_id,cat_name FROM " .$ecs->table('category'). " where parent_id = ". $row_2['cat_id'] ." ORDER BY cat_id asc";
$res_3 = $db->query($sql_3);
print "****** 二级分类:" . $row_2['cat_name'] ."<br>";
//二级类目子类目循环
$keyword_2 = '';
$c3 = 0;
while ($row_3 = $db->fetchRow($res_3))
{
$c3 = $c3 + 1;
if ($c3 < 7)
{
//生成二级类目的关键词和描述
$keyword_2 = $keyword_2 . replace_cat_name($row_3['cat_name']) . ", ";
}
//=====================================================================
//取得三级类目子类目
$sql_4 = "SELECT cat_id,cat_name FROM " .$ecs->table('category'). " where parent_id = ". $row_3['cat_id'] ." ORDER BY cat_id asc";
$res_4 = $db->query($sql_4);
print "********* 三级分类:" . $row_3['cat_name'] ."<br>";
//三级类目子类目循环
$keyword_3 = '';
$c4 = 0;
while ($row_4 = $db->fetchRow($res_4))
{
$c4 = $c4 + 1;
if ($c4 < 7)
{
//生成三级类目的关键词和描述
$keyword_3 = $keyword_3 . replace_cat_name($row_4['cat_name']) . ", ";
}
//直接写三级类目的值
print "************ 四级分类:" . $row_4['cat_name'] ."<br>";
$cat_name_4_str = replace_cat_name($row_4['cat_name']);
$keyword_4_str = $cat_name_4_str . " Products, Online Shopping, Taobao Agent, Taobao Dropship";
$desc_4_str = "Online shopping ". $cat_name_4_str ." Products from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
$db->query("UPDATE " .$ecs->table('category'). " SET keywords ='". $keyword_4_str ."', cat_desc ='". $desc_4_str ."' WHERE cat_id =". $row_4['cat_id'] ."");
}
//对三级类目字符串进行处理更新
$cat_name_3_str = replace_cat_name($row_3['cat_name']);
if (substr($keyword_3,-2) == ', ')
{
$keyword_3 = substr($keyword_3,0,strlen($keyword_3)-2);
}
if ($keyword_3 == '')
{
$keyword_3_str = $cat_name_3_str . " Products";
$desc_3_str = "Online shopping ". $cat_name_3_str ." Products, Browse Through Our Category of ". $cat_name_3_str . " Products and more from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
}
else
{
$keyword_3_str = $cat_name_3_str . ", ". $keyword_3 . " Products";
$desc_3_str = "Online shopping ". $cat_name_3_str ." Products, Browse Through Our Categories of ". $keyword_3 . " Products and more from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
}
$db->query("UPDATE " .$ecs->table('category'). " SET keywords ='". $keyword_3_str ."', cat_desc ='". $desc_3_str ."' WHERE cat_id =". $row_3['cat_id'] ."");
}
//对二级类目字符串进行处理更新
$cat_name_2_str = replace_cat_name($row_2['cat_name']);
if (substr($keyword_2,-2) == ', ')
{
$keyword_2 = substr($keyword_2,0,strlen($keyword_2)-2);
}
if ($keyword_2 == '')
{
$keyword_2_str = $cat_name_2_str . " Products";
$desc_2_str = "Online shopping ". $cat_name_2_str ." Products, Browse Through Our Category of ". $cat_name_2_str . " Products and more from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
}
else
{
$keyword_2_str = $cat_name_2_str . ", ". $keyword_2 . " Products";
$desc_2_str = "Online shopping ". $cat_name_2_str ." Products, Browse Through Our Categories of ". $keyword_2 . " Products and more from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
}
$db->query("UPDATE " .$ecs->table('category'). " SET keywords ='". $keyword_2_str ."', cat_desc ='". $desc_2_str ."' WHERE cat_id =". $row_2['cat_id'] ."");
//=====================================================================
}
//对一级类目字符串进行处理更新
$cat_name_1_str = replace_cat_name($row_1['cat_name']);
if (substr($keyword_1,-2) == ', ')
{
$keyword_1 = substr($keyword_1,0,strlen($keyword_1)-2);
}
$keyword_1_str = $cat_name_1_str . ", ". $keyword_1 . " Products";
$desc_1_str = "Online shopping ". $cat_name_1_str ." Products, Browse Through Our Categories of ". $keyword_1 . " Products and more from ". $GLOBALS['_CFG']['shop_name'] .", Factory Price, Worldwide Shipping!";
$db->query("UPDATE " .$ecs->table('category'). " SET keywords ='". $keyword_1_str ."', cat_desc ='". $desc_1_str ."' WHERE cat_id =". $row_1['cat_id'] ."");
}
function replace_cat_name($cate_name)
{
$str = str_replace(' ,',',',str_replace(' ',' ',str_replace(' &',', ',str_replace('&',', ',str_replace(' /','/',str_replace('/',', ',addslashes($cate_name)))))));
return $str;
}
?>
|
最近更新
常用插件
- ecshop2.7.1邮件发送插件
ecshop2.7.1邮件发送插件:该插件主要的开发思想是源于ecshop短信发送系统...
- ecshop最小购买数量控制插
ecshop最小购买数量控制插件,这个插件主要是为我们提供一个十分方便...
- ecshop二次开发商品购买增
图片1香...
- ecshop2.7.2生成虚拟订单2.
以前我们开发过ecshop下的虚拟订单,就是客户在访问的时候,会自动生...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...
ecshop热门问答
ecshop热门资料
ecshopblue
ecshop米客
ecshop两者
ecshop高手请帮帮我!!!
ecshop探讨
ecshop收款插件
ecshop便利店
ecshop点击下载
ecshop管理工具
ecshop安装程序幕
ecshop业绩
ecshopwap客户端
ecshop薪酬
hantoomjs
ecshop手机浏览器
ecshop提交订单错误
ecshop字节
ecshop微录手表
ecshopGBK与UTF-8
ecshop广州移动
ecshop输入关键词
ecshop浏览服务器
ecshop尺寸
ecshop导出excel
ecshop毕??
ecshop商品重量
ecshop程序员
ecshopcode
ecshopECMAIL
ecshop压缩输出