PHPBB的sitemap制作,生成有利于SEO的网址

本文提供了一个用于生成PHPBB论坛站点地图的PHP脚本。通过调整脚本中的变量,可以将其应用于不同域名和路径的论坛上。该脚本能够自动生成符合Sitemap标准的XML文件,便于搜索引擎抓取。

将以下PHP文件放到你网站的根目录就OK了。


 

加入此sitemap的前提是,必须将PHPBB论坛的默认URL规格改成以下文件里生成的格式,这里有具体方法:http://blog.youkuaiyun.com/huangqiaoling/article/details/7652111

 

注意红色部分的代码,要改成你网站对应的内容:

<?php

// By: Arlinger On 2012-6-4
// If you have any questions, please email:
Arlinger@foxmail.com


// CUSTOM INSTALLATION VARIABLES:
 $subdomain='www.'; 
 $domain=' ';  //这里要改成你的网站名
 $folder='/forum/';                  //这里要改成你把博客所在的文件夹的名字
 $urls=50000;

// Change Nothing Below Here:
$domainpath='http://'.$subdomain.$domain.$folder;

// Connect
define('IN_PHPBB', true);
$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);


// Gzip compression
 if (@extension_loaded('zlib') && !headers_sent())
 {
  ob_start('ob_gzhandler');
 }


// Send Header
header("Content-Type: text/xml;charset=iso-8859-1"); 

// Send initial Data
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo '<urlset xmlns="
http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";

// Send Index
$current_time=time();

echo '<url>
      <loc>'.$domainpath.'</loc>
<lastmod>'.date("Y-m-d\TH:i:sP",$current_time).'</lastmod>
         </url>';

$urls=$urls-1;


// Send Forums
$sql = 'SELECT forum_id, forum_last_post_time FROM '.$table_prefix.'forums WHERE enable_indexing=1 LIMIT '.$urls;
     $result = $db->sql_query($sql);
 while ($data=$db->sql_fetchrow($result)) {

// Fix for parents forums showing 1969
if ($data['forum_last_post_time'] == 0) {
$data['forum_last_post_time']=$current_time;}

echo '<url>
      <loc>'.$domainpath.'viewforum-'.$data['forum_id'].'.html'.'</loc>
<lastmod>'.date("Y-m-d\TH:i:sP",$data['forum_last_post_time']).'</lastmod>

         </url>';

$urls=$urls-1;

}
$db->sql_freeresult($result);


// Send Topics
$sql = 'SELECT * FROM '.$table_prefix.'topics as t, '.$table_prefix.'forums as f WHERE t.topic_approved=1 AND t.forum_id=f.forum_id AND f.enable_indexing=1 ORDER BY t.topic_id DESC LIMIT '.$urls;
     $result = $db->sql_query($sql);
 while ($data=$db->sql_fetchrow($result)) {

echo '<url>
      <loc>'.$domainpath.'viewtopic-'.$data['topic_id'].'.html'.'</loc>
<lastmod>'.date("Y-m-d\TH:i:sP",$data['topic_last_post_time']).'</lastmod>
         </url>';
}
$db->sql_freeresult($result);


// Send Closing Tags
echo '  </urlset>';

?>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值