zoukankan      html  css  js  c++  java
  • ECshop网点程序优化-自动生成类目页Keywords、Desciption Meta

    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;
    }
    ?>

    转载:http://blog.sina.com.cn/s/blog_70ea94110101h5dd.html

  • 相关阅读:
    10 个雷人的注释,就怕你不敢用!
    Java 14 之模式匹配,非常赞的一个新特性!
    poj 3661 Running(区间dp)
    LightOJ
    hdu 5540 Secrete Master Plan(水)
    hdu 5584 LCM Walk(数学推导公式,规律)
    hdu 5583 Kingdom of Black and White(模拟,技巧)
    hdu 5578 Friendship of Frog(multiset的应用)
    hdu 5586 Sum(dp+技巧)
    hdu 5585 Numbers
  • 原文地址:https://www.cnblogs.com/wawahaha/p/4621446.html
Copyright © 2011-2022 走看看