分享

PHPBB生成sitemap地图文件的方法

 xf_baby 2013-11-14

发布:thatboy   来源:脚本学堂     【  

本文介绍下,在PHPBB论坛中生成sitemap地图文件的实现代码,感兴趣的朋友参考学习下。

将以下PHP文件放到网站的根目录。
加入此sitemap的前提:
必须将PHPBB论坛的默认URL规格改成以下文件里生成的格式。

具体方法,请参考:
http://www./article/13591.html
 
注意:
红色部分的代码,修改成自己网站对应的内容:
 

复制代码代码示例:

<?php
// By: Arlinger On 2012-6-4 
//

// 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./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>';
?>

本文地址:http://www./article/13592.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多