我正在尝试创建一个会自动更新的站点地图。 我已经用我的RSS源文件做了类似的事情,但是这个站点地图不起作用。 您可以在http://designdeluge.com/sitemap.xml上实时查看它。 我认为主要问题是它无法识别PHP代码。 这是完整的源代码:
<?php
include 'includes/connection.php';
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>
<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>http://designdeluge.com/</loc>
<lastmod>2010-04-20</lastmod>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>http://designdeluge.com/about.php</loc>
<lastmod>2010-04-20</lastmod>
<changefreq>never</changefreq>
<priority>0.5</priority>
</url>
<?php
$entries = mysql_query("SELECT * FROM Entries");
while($row = mysql_fetch_assoc($entries)) {
$title = stripslashes($row['title']);
$date = date("Y-m-d", strtotime($row['timestamp']));
echo "
<url>
<loc>http://designdeluge.com/".$title."</loc>
<lastmod>".$date."</lastmod>
<changefreq>never</changefreq>
<priority>0.8</priority>
</url>";
} ?>
</urlset>
问题在于动态URL(例如从数据库中获取的URL)未被生成,因此网站地图无法验证。谢谢!编辑:目前,我只是试图使代码本身正常工作。我将其设置为我的本地测试服务器上的PHP文件。上面的代码正在使用。目前,在屏幕上或源代码中没有显示任何内容。我认为我可能犯了语法错误,但我找不到任何错误。感谢您的任何帮助!
编辑2:好了,伙计们,我解决了。显然,我必须用PHP输出XML声明。最终的代码已发布在上面。感谢您的帮助!