php网站地图生成,php生成网站地图 php 生成sitemap完整例子 源码下载

require_once $_SERVER['DOCUMENT_ROOT'] . '/php/coon.php';

//服务

$url = 'https://你的域名/';

$cs = '.html';

$txt3 = $url.'service';

$url1 = array();

//修改成你的数据库没有分类的生成

$rs = $pdo->query("select * from web_txt where nav = 7 or nav = 9 or nav = 11 or nav = 12 ");

$t1 = 0;

while ($row = $rs->fetch()) {

$url1[$t1] = $txt3.$row['id'].$cs;

$t1++;

}

//第二个表有分类的列表页生成

$txt9 = $url.'page';

$rs4 = $pdo->query("select * from web_news_left order by orders desc,id desc");

$n=10;

while ($row4 = $rs4->fetch()) {

$url1[$t1] = $txt9.$n.$cs;

if($n == 10){

$url1[$t1] = $txt9.'4'.$cs;

}

$t1++;

$n++;

}

//第三个表有分类的详细页生成

$txt10 = $url.'news';

$rs5 = $pdo->query("select * from web_news order by id desc");

while ($row5 = $rs5->fetch()) {

$url1[$t1] = $txt10.$row5['id'].$cs;

$t1++;

}

//其他单页面生成

$url1[$t1] = $url.'index.html';

$t1++;

$url1[$t1] = $url.'page1.html';

$t1++;

$url1[$t1] = $url.'page6.html';

$t1++;

$url1[$t1] = $url.'page5.html';

$t1++;

$url1[$t1] = $url.'page3.html';

//将所有数据生成sitemap

$content='<?xml version="1.0" encoding="UTF-8"?>

xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">';

$num = count($url1);

for($i=0; $i

$content.="

";

$content.="".$url1[$i]."

";

//电脑站的标识 手机站为$content.='';

$content.='';

$content.="

";

}

$content.='

';

$fp=fopen('../sitemap.xml','w+');

fwrite($fp,$content);

fclose($fp);

echo '生成PC Sitemap.xml 成功
';

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值