首页 > 网站 > 建站经验 > 正文

优化ecshop自动生成类目页Keywords、Desciption Meta

2024-04-25 20:43:28
字体:
来源:转载
供稿:网友

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;

}

?>

以上就是本文章的内容,希望对大家有所帮助

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表