Sitemap可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页。最简单的 Sitemap 形式,就是XML 文件,在其中列出网站中的网址以及关于每个网址的其他元数据(上次更新的时间、更改的频率以及相对于网站上其他网址的重要程度为何等),以便搜索引擎可以更加智能地抓取网站。
第一步:打开admin/include目录下的mymps.menu.inc.php文件第16行添加
$admin_menu[siteabout][group][element]['其他站务']['生成百度地图']='information.php?action=makebaiduxml';
添加完成到后台刷新,见下图会出现【生成百度地图】选项
第二步:打开admin目录下information.php文件第332行下添加
如果332行添加代码出错,搜索else if ($action == 'edit') {在此行代码上添加下面代码
else if ($action == 'makebaiduxml') {
chk_admin_purview('purview_分类信息');
//$admindir = getcwdOL();
$where = 'WHERe 1';
$where .= ($info_level != '' ? ' AND a.info_level = \'' . $info_level . '\'' : '');
switch ($info_level) {
case '0':
$here = '待审 ';
break;
case '1':
$here = '正常 ';
break;
case '2':
$here = '推荐 ';
break;
}
$here .= '分类信息列表';
$rows_num = $db->getOne('SELECt COUNT(a.id) FROM `' . $db_mymps . 'information` AS a ' . $where);
$param = setParam(array('part', 'show', 'keywords', 'info_level', 'upgrade', 'ifred', 'ifbold', 'certify'));
$information = array();
//$idin = get_page_idin('id', 'SELECt a.id FROM `' . $db_mymps . 'information` AS a ' . $where . ' ORDER BY a.id DESC');
//$page1 = ($idin ? $db->getAll('SELECt a.*,b.catname,b.dir_typename FROM `' . $db_mymps . 'information` AS a LEFT JOIN `' . $db_mymps . 'category` AS b ON a.catid = b.catid WHERe a.id in (' . $idin . ') ORDER BY a.id DESC') : array());
$page1 = $db->getAll('SELECt a.*,b.catname,b.dir_typename FROM `' . $db_mymps . 'information` AS a LEFT JOIN `' . $db_mymps . 'category` AS b ON a.catid = b.catid WHERe 1 ORDER BY a.id DESC LIMIT 1000');
$sitemap = "
xmlns:mobile=\"http://www.baidu.com/schemas/sitemap-mobile/1/\">\r\n";
$sitemap .= "\r\n";
foreach ($page1 as $k => $row ) {
$arr['id'] = $row['id'];
$arr['uri'] = Rewrite('info', array('dir_typename' => $row['dir_typename'], 'id' => $row['id']));
$arr['uri_cat'] = '?keywords=' . $row[catid] . '&show=catidno';
$arr['levelid'] = $row['levelid'];
$arr['ip'] = $row['ip'];
$arr['certify'] = $row['certify'];
$arr['ip2area'] = $row['ip2area'];
$arr['contact_who'] = ($row['userid'] ? '' . $row[userid] . '' : $row['contact_who']);
$arr['title'] = $row['title'];
$arr['catid'] = $row['catid'];
$arr['catname'] = $row['catname'];
$arr['img_path'] = $row['img_path'];
$arr['ifred'] = $row['ifred'];
$arr['ifbold'] = $row['ifbold'];
$arr['begintime'] = $row['begintime'];
$arr['ip'] = $row['ip'];
$arr['info_level'] = $information_level[$row[info_level]];
$arr['directory'] = $db -> getOne("SELECt directory FROM `{$db_mymps}city` WHERe cityid = '$row[cityid]'");
$arr['infouri'] = $mymps_global[SiteUrl].$mymps_global['cfg_citiesdir'].'/'.$arr['directory'].'/'.$arr['uri'];
$sitemap .= "\r\n";
}
$sitemap .= '';
$file = fopen("../sitemap.xml","w");
fwrite($file,$sitemap);
fclose($file);
echo '百度sitemap生成成功';
$idin = NULL;
}
到此已经全部修改完成,到后台试一下。点击【生成百度地图】后出现下方提示就已经成功了。
生成后在你的网站根目录会出现一个sitemap.xml文件,表示你已经大功告成。