Bigcommerce:给51eCommerce Knowledge Manager制作sitemap

Bigcommerce是比较灵活的一个购物系统,他的后台比较完善,只要在服务器下添加一个Help目录,在Settings—>Knowledge Manager里,做些接口的相关配置,并安装好51eCommerce Knowledge Manager,就有一个很实用的‘帮助中心’了。但
这个知识库本身存在一些缺陷,需要我们自己完善。当我们需要提交Help里的URL给google抓取,就需要我们自己写代码了。今天把这个sitemap的代码给写出来了,具体如下:

第一步:在Help目录下建一个config.php

<?php
// Do not change anything in this file!
$dbms = 'mysql';        //your database Connection file name
$dbhost = 'localhost';  //your database hosting address
$dbport = '';
$dbname = 'ipcamera_supp';  //your database name
$dbuser = 'ipcamera_supp';  //your database user name
$dbpasswd = '10Rswk3gm-4';  //your database password
$table_prefix = 'ikm_';     //your database table prefix
$acm_type = 'file';
$load_extensions = '';
?>

第二步:连接数据库

1.在includes目录下建一个名为:db的文件夹,上传写好的sql文件(我写了俩个:dbal.php和mysql.php)。这里就不把文件内容写出来了,很基础的东西。

第三步:建立sitemap.php

<?php
   define('NO_SESSION', true); 
 
    ob_start('ob_gzhandler');
 
    $subdomain='www.'; 
    $domain='ipcamera.biz';
    $folder='/support/'; 
    $domainpath='http://'.$subdomain.$domain.$folder;

    $urls=50000;
   
    $phpbb_root_path = './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);  
 
    include($phpbb_root_path . 'config.' . $phpEx);   
    include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
   
    $db = new $sql_db();
    $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
   
   
    header('Content-type: text/xml; charset: UTF-8');
    echo '<?xml version="1.0" encoding="UTF-8"?>',"\n";
    echo '<urlset xmlns="
http://www.sitemaps.org/schemas/sitemap/0.9">',"\n";
 
    $current_time=time();

    // index page
    echo '<url>
      <loc>'.$domainpath.'</loc>
      <lastmod>'.date("Y-m-d\TH:i:sP",$current_time).'</lastmod>
         </url>';
      $urls=$urls-1;
   
  
     //question title list
 $sql = 'SELECT questionid,title,lastupdated FROM '.$table_prefix.'questions LIMIT '.$urls; 
 $result = $db->sql_query($sql);
 while ($data=$db->sql_fetchrow($result)) {
     if ($data['forum_last_post_time'] == 0) {$data['lastupdated']=$current_time;}

     $title=$data['title'];
     $linkName=makeSafeUrl($title);
    
     echo '<url>
         <loc>'.$domainpath.'questions/'.$data['questionid'].'/'.$linkName.'</loc>
         <lastmod>'.date("Y-m-d\TH:i:sP",$data['lastupdated']).'</lastmod>
         </url>';

         $urls=$urls-1;
   }
 
   $db->sql_freeresult($result);
 
 
 

 echo '</urlset>',"\n";

 ob_end_flush();

 function makeSafeUrl($url)
 {
  // We can't just pass ENT_QUOTES to htmlspecialchars because that converts a ' to &#39; rather than &apos;
  // Google sitemaps requires ' to be encoded as &apos; so we have to do things a little differently
  $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8'); 
  $url = str_replace(" ", '+', $url);
  
  $str= '?';         
        $c=explode($str,$url);
        if(count($c)> 1){         
          $url = $url.'%3F';   
        }
        return $url;
 }
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值