This is my first PHP page. It is a plugin of PHPDug which can generate google sitemap. I hope it is useful for you.
You can download from here sitemap.php.zip directly or visit my blog http://www.linglihu.com/post/SitemapPluginForPHPDug.html.
这是我的第一个PHP的"程序" , PHPDug的Sitemap插件,希望对你有用. 你可以从这里下载sitemap.php.zip.
<?php
//Code by zitiger at http://www.linglihu.com
require_once('includes/config.php');
require_once('includes/functions/func.global.php');
db_connect($config);
header( "Content-type: application/xml; charset=\"utf-8\"", true );
header( 'Pragma: no-cache' );
generate_header();
$query = "SELECT story_id,story_time FROM ".$config['db']['pre']."stories";
$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
while ($info = @mysql_fetch_array($query_result))
{
$result="\n";
$result .= "\t<url>\n\t\t<loc>".$config['site_url'].'story.php?id='.$info['story_id']."</loc>\n";
// lastmod
$result .= "\t\t<lastmod>".$info['story_time']."</lastmod>\n";
// changefreq
$result .= "\t\t<changefreq>weekly</changefreq>\n";
// priority
$result .= "\t\t<priority>0.8</priority>\n";
$result .= "\t</url>";
print $result;
}
generate_footer();
function generate_header()
{
$header = "<\x3Fxml version=\"1.0\" encoding=\"utf-8\"\x3F>\n<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">";
print $header;
}
function generate_footer()
{
$footer = "\n</urlset>";
print $footer;
}
?>