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 ' rather than '
// Google sitemaps requires ' to be encoded as ' 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;
}