mymps添加Sitemap网站地图功能

Sitemap(站点地图)是一种文件,站长可通过该文件列出网站上的网页,将网站内容的组织结构告知搜索引擎。百度等搜索引擎网页抓取工具会读取此文件,以便更加智能地抓取网站内容。

需要注意的是,百度等搜索引擎会按正常流程分析、处理Sitemap,但不保证一定会抓取及索引您提交的所有网址,不保证其在搜索结果中的排名。

在mymps或者vbmcms中创建sitemap网站地图功能:

第一步:添加后台点击生成链接

打开admin/include目录下的mymps.menu.inc.php文件第16行后添加代码:

$admin_menu[siteabout][group][element]['其他站务']['生成百度地图']='information.php?action=makebaiduxml';

添加完成到后台刷新,出现如下图所示出现【生成百度地图】链接导航即可。

第二步:添加功能实现代码

打开admin目录下的information.php文件,在第332行下或者396行下(如果行数不对,请搜索elseif ($action == 'edit')在elseif{***}下方)添加以下代码:

elseif (strstr($action, 'level')) {//生成sitemap地图
			require_once MYMPS_MEMBER . '/include/common.func.php';
			$action = FileExt($action);
			$id = explode(',', $id);
			!is_array($id) && _func_0('您没有选中任何记录!');
			foreach ($id as $k => $v) {
				$get_row = is_member_info($v, 'no_level_limit');
				if ($get_row['ismember'] == 1) {
					$userid = $get_row['userid'];
					if ($if_money == 1) {
						$db->query("UPDATE `{$db_mymps}member` SET money_own = money_own {$money_num} WHERE userid = '$userid'");
					}
					if ($if_pm == 1) {
						$title = str_replace('{title}', $get_row[title], $title);
						$title = str_replace('{action}', $information_level[$action], $title);
						$result = sendpm($admin_id, $userid, $title, $msg, 1);
					}
				}
				$db->query("UPDATE `{$db_mymps}information` SET info_level = '$action' WHERE id = '$v'");
			}
			$id = empty($id) ? 0 : join(',', $id);
			write_msg('课程 ' . $id . ' 状态转为 ' . $information_level[$action] . ' 成功!', $url, 'REcord');
		}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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
xmlns:mobile=\"http://www.baidu.com/schemas/sitemap-mobile/1/\">\r\n";  
$sitemap .= "<url>\r\n"."<loc>".$mymps_global[SiteUrl]."</loc>\r\n"."<lastmod>".date('Y-m-d')."</lastmod>\r\n<changefreq>weekly</changefreq>\r\n<priority>0.6</priority>\r\n</url>\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'] ? '<a href="javascript:void(0);""setbg(\'Mymps会员中心\',400,110,\'../box.php?part=member&userid=' . $row['userid'] . '&admindir=' . $admindir . '\')">' . $row[userid] . '</a>' : $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 .= "<url>\r\n"."<loc>".$arr['infouri']."</loc>\r\n"."<lastmod>".date('Y-m-d',$row['begintime'])."</lastmod>\r\n<changefreq>weekly</changefreq>\r\n<priority>0.6</priority>\r\n</url>\r\n";
		}
$sitemap .= '</urlset>'; 
$file = fopen("../sitemap.xml","w");
        fwrite($file,$sitemap);
        fclose($file);
		echo '<a href="'.$mymps_global[SiteUrl].'/sitemap.xml"/ target="_blank">百度sitemap</a>生成成功';
		$idin = NULL;
	}

到此已经全部修改完成,到后台试一下。点击【生成百度地图】后出现“百度sitemap生成成功”就已经成功了。

原文链接:https://www.moxiaoseo.com/mx-834.html,转载请注明出处。

0
广告位招租

评论0

站点公告

新的一年祝各位站长:虎年吉祥,虎虎生威!新年发小财!新用户注册即送5次下载,全站90%以上资源都可下载。
没有账号? 注册  忘记密码?

社交账号快速登录

'); })();