« Google Sitemaps (BETA) | 首页 | Opera v8.01 build 7624最新测试版 »

分类: 志中痣

2005年06月05日

Movable Type的Sitemap模板及其他生成器

  关于Google Sitemaps已在前面一篇日志里介绍过了,这里讲快速地为Movable Type制作Sitemap模板。原来考虑用插件的方式,因为不熟悉Perl,于是跑去Pronet求助,幸亏Niall Kennedy提醒使用MT强大的模板定制系统,此外还临时收集几个其他的Sitemap生成器......

Movable Type Sitemap模板,在Manage - Templates - Create new index template,用以下代码创建,Output File设为sitemap.xml,然后rebuild即可,如果中文出现乱码,建议使用先把以下代码一UTF-8编码另存为模板文件,然后Link this template to a file连接到此文件
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
 <url>
  <loc><$MTBlogURL encode_xml="1"$></loc>
  <priority>1.0</priority>
 </url>
 <MTEntries lastn="9999">
 <url>
  <loc><$MTEntryPermalink encode_xml="1"$></loc>
  <lastmod><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></lastmod>
 </url>
 </MTEntries>
</urlset>


WordPress用户可以使用以下Sitemap Generator
<?php require('wp-blog-header.php');
header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<!-- generator="http://www.socialpatterns.com/"-->
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
 <url>
  <loc><?php bloginfo('url') ?></loc>
  <lastmod><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></lastmod>
  <changefreq>always</changefreq>
  <priority>1.0</priority>
 </url>
 <?php $sitemap = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER by post_modified DESC"); ?>
 <?php foreach ($sitemap as $sitemap) { ?>
 <url>
  <loc><?php echo get_permalink($sitemap->ID); ?></loc>
  <lastmod><?php echo mysql2date('Y-m-d\TH:i:s\Z', $sitemap->post_modified, false); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
 <?php } ?>
</urlset>


Serendipity用户可以使用以下Sitemap Generator
<?php
include_once('serendipity_config.inc.php');
header("Content-type: text/xml");
$doc = domxml_new_doc("1.0");

$root = $doc->add_root("urlset");

$url = $root->new_child("url");

$loc = $url->new_child("loc", $serendipity['baseURL']);
$lastmod = $url->new_child("lastmod", date("Y-m-d", time()));
$changefreq = $url->new_child("changefreq", "daily");
$priority = $url->new_child("priority", "0.0");

$entries = serendipity_fetchEntries();

foreach($entries as $entry) {
 $url = $root->new_child("url");
 $loc = $url->new_child("loc", sprintf("%s%s", rtrim($serendipity['baseURL'], "/"), serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath')));

 $lastmod = $url->new_child("lastmod", date("Y-m-d",$entry['timestamp']));
 $changefreq = $url->new_child("changefreq", "never");
 $priority = $url->new_child("priority", "1.0");
}

echo ($doc->dump_mem());
$doc->dump_file("Sitemap", false, false);
system("gzip Sitemap");
system("gzip create_sitemap.php");
?>


vBulltin Board(vBB)用户可以使用以下Sitemap Generator
<?php

// enter host , user, password database
$host = '';
$user = '';
$password = '';
$database = '';

// base url of the forum with trailing slash, table prefix if any, $base = '';
$prefix = '';
// home page if different than the base url for the forum
$home = '';

// the var string for forum display
// if your url is forumdisplay.php?f=73 then this would be f=
$forumq = '';
// the var string for your thread display
// if your url is showthread.php?t=872 then is t=
$threadq = '';
// url text file name make it writable!!!
$file = '';
// new line character \r\n for widnows \n for unix
$nl = "\n";
// forum priority , tread priority, change frequency tread and forum see the sitemaps dcumentation
$fpriority = "0.8";
$tpriority = '1.0';
$fchange ='hourly' ;
$tchange ='weekly';
// base and forum base change and priority
$bchange ='hourly';
$bpriority = '1.0';
// end variabless

$fpriority = "priority=".$fpriority;
$tpriority = "priority=".$tpriority;
$fchange = "changefreq=".$fchange;
$tchange = "changefreq=".$tchange;
$bchange = "changefreq=".$bchange;
$bpriority = "priority=".$bpriority;

$basestr = " $bchange $bpriority";
$fstr = " $fchange $fpriority";
$tstr = " $tchange $tpriority";

 $connection = mysql_connect($host, $user, $password ) or die("Database is down please try again");
 $db = mysql_select_db($database, $connection) or die ("NO DATABASE" );

$handle = fopen("$file", "w");
 fwrite($handle, $home.$basestr.$nl);

 fwrite($handle, $base.$basestr.$nl);
$forums = $prefix."forum";
$treads = $prefix."thread";
$fquery = "SELECT forumid FROM $forums";

$results = mysql_query($fquery) or DIE("$fquery" );
$num_rows = mysql_num_rows($results);

for ( $i = 0; $i < $num_rows; $i++)
 {

  $row = mysql_fetch_row($results);
  print_r($row);
  $url = $base."forumdisplay.php?".$forumq.$row[0].$fstr.$nl;
  fwrite($handle, $url);
 }

$tquery = "SELECT threadid FROM $treads";

$results = mysql_query($tquery) or DIE("$tquery" );
$num_rows = mysql_num_rows($results);

for ( $i = 0; $i < $num_rows; $i++)
 {
  $row = mysql_fetch_row($results);
  print_r($row);
  $url = $base."showthread.php?".$threadq.$row[0].$tstr.$nl;
  fwrite($handle, $url);
 }

fclose($handle);

?>


一个ASP/ASP.NEt的Sitemap Generator,可以存为.asp或.aspx
<%
' sitemap_gen.asp
' A simple ASP script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
' by Francesco Passantino
' www.iteam5.net/francesco/sitemap_gen
' v0.1 released 4 june 2005
'
' BSD 2.0 license,
' http://www.opensource.org/licenses/bsd-license.php



'modify this to change website and root folder
session("server")="http://www.yousite.net"
vDir = "/blog/"



MAXURLS_PER_SITEMAP = 50000
set fso = CreateObject("Scripting.FileSystemObject")
root = Server.MapPath(vDir) &"\"
set fold = fso.getFolder(root)

response.ContentType = "text/xml"
response.write "<?xml version='1.0' encoding='UTF-8'?>"
response.write "<!-- generator='http://www.iteam5.net/francesco/sitemap_gen'-->"
response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"

if fold.subfolders.count > 0 then
 for each f in fold.subfolders
  sfoldname = root &f.name &"\"
  fpath = vDir &f.name &"/"

  if folderpermission(fpath) then
   set cfold = fso.getFolder(sfoldname)
   if cfold.subfolders.count > 0 or cfold.files.count > 0 then
    for each sf in cfold.subfolders
     sfoldname = root &f.name &"\" &sf.name &"\"
     path = vDir &f.name &"/" &sf.name &"/"
     set sfold = fso.getFolder(sfoldname)
     if sfold.files.count > 0 then
      for each fil in sfold.files
       response.write getfilelink(path, fil)
      next
     end if
    next
    for each fil in cfold.files
     response.write getfilelink(fpath, fil)
    next
   else
    response.Write getfoldlink(cfold, fpath)
   end if
   if session("URLS")=MAXURLS_PER_SITEMAP then exit for
  end if
 next
end if

if session("URLS")<MAXURLS_PER_SITEMAP then
 for each fil in fold.files
  response.write getfilelink(vDir, fil)
 next
end if

response.write "</urlset>"
set fso = nothing


Function getfilelink(fold, file)
 If FileExtensionIsBad(file) then Exit Function
 filelmdate=file.dateLastModified
 if month(filelmdate)<10 then filedatem="0"
 if day(filelmdate)<10 then filedated="0"

 filedate=year(filelmdate)&"-"&filedatem&month(filelmdate)&"-"&filedated&day(filelmdate)
 getfilelink = "<url><loc>"&server.htmlencode(session("server")&fold&file.name)&"</loc><lastmod>"&filedate&"</lastmod><priority>1.0</priority></url>"
 session("URLS")=session("URLS")+1
 Response.Flush
End Function

Function Folderpermission(pathName)

 'modify this to exclude path
 PathExclusion=Array("/test1/","/test/test2/")
 Folderpermission =True
 for each PathExcluded in PathExclusion
  if ucase(pathName) = ucase(PathExcluded) then
   Folderpermission = False
   exit for
  end if
 next
End Function

Function FileExtensionIsBad(sFileName)
 Dim sFileExtension, bFileExtensionIsValid, sFileExt

 'http://www.googleguide.com/file_type.html
 Extensions = Array("gif","jpg","zip","pdf","ps","html","htm","asp","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","wks","wps","wdb","wri","rtf","ans","txt")

 if len(trim(sFileName)) = 0 then
  FileExtensionIsBad = true
  Exit Function
 end if

 sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
 bFileExtensionIsValid = false'assume extension is bad
 for each sFileExt in extensions
  if ucase(sFileExt) = ucase(sFileExtension) then
   bFileExtensionIsValid = True
   exit for
  end if
 next
 FileExtensionIsBad = not bFileExtensionIsValid
End Function
%>


  另外,这是一个可以直接从本地目录生成Sitemap的脚本,更有人已经打算干起专门为人手工制作Sitemap的营生,祝他能赚到大把美刀,呵呵。

  最后,如果你并不是什么IT Pro,对脚本之类根本一窍不通,只是个普通的上网者或blogger,也不想自己制作Sitemap,OK,用记事本新建一个文本文件,把网址一个个复制粘贴进去,一行一个,比如:

http://plod.popoever.com/archives/000001.html
http://plod.popoever.com/archives/000002.html
http://plod.popoever.com/archives/000003.html
.
.
.

然后存为sitemap.urllist(保存时文件类型选“全部”),把这个文件上传到网站根目录下,比如http://plod.popoever.com/sitemap.urllist,再通过添加页面提交给Google,Google审核后会为你生成并提供你下载,不过Google也申明不保证所有这样提交的申请都被及时生成。好了,很多人在说变“被动”为“主动”,我只想说,是“互动”。

Posted by POPOEVER at 2005年06月05日 15:15 | back to top
Featured

Trackback Pings

本篇日志的回溯引用地址:

http://plod.popoever.com/acp630/mt-tb.cgi/581

Listed below are links to weblogs that reference 'Movable Type的Sitemap模板及其他生成器' from Plod.


  1. #1265

    » Movable Type的Sitemap模板及其他生成器 from En8's Blog
      关于[url=https://www.google.com/webmasters/sitemaps] Google Sitemaps[/url][url=http://www.en8.net/blog/article.asp?id=307]已在前面一篇日志 [/url]里介绍过了,这里讲快速地为[url=http://www.movabletype.org/]Movable Type [/url]

    Tracked on 2005年06月06日 09:13 from this weblog | back to top

  2. #2006

    » links for 2006-01-27 from XXC@Blog
    Plod: Google Sitemaps (BETA) Google Sitemap 介紹 (tags: Googel_Sitemaps) Google Sitemaps Google Sitemaps: 協助網站管理者分析網站內容的工具 (tags: Google_Sitemaps WebToolService WebDesignTool Statistics) Plod: Movable Type的Sitemap

    Tracked on 2006年01月27日 23:13 from this weblog | back to top

  3. #12558

    » movable type 也可以制作google sitemap网站地图 from 花边的网络
    http://plod.popoever.com/archives/000557.html 介绍了如何制作google sitemap的方法。我也不多说。实际上http://www.webmasterview.com/markup/google_sitemap_movable_type_template也有介绍,不过是英文的。我补充两点。 * sit...

    Tracked on 2006年09月02日 22:46 from this weblog | back to top

Comments


  1. #4476

    good site, good short contents of the good work. Congratulations !

    Posted by Halo at 2006年01月16日 13:32 | back to top

  2. #4478

    I love this site so so so much :) Cool site!!

    Posted by Dominic at 2006年01月16日 13:34 | back to top

  3. #197582

    你好,我們最近建立了Movable Type 4的中文支援站,希望能請您一起來共襄盛舉,來我們的網站發表您的意見,讓開放原始碼之後的MT在台灣使用率更高,感謝。

    網址是:
    http://www.movabletypetw.org

    Posted by Movable Type中文支援站 at 2007年06月21日 15:38 | back to top

Post a comment

说老实话,做开心人,欢迎您留露箴言
即便如此,也请遵纪守法,勿放厥辞
汝国如汝母,辱国如辱母,吾辈当自强
您的观点仅代表个人,与本站无关,望请自尊

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?