【发布时间】:2011-02-14 10:09:53
【问题描述】:
我正在尝试创建一个会自动更新的站点地图。我用我的 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 声明。最终代码贴在上面。感谢您的帮助!
【问题讨论】:
标签: php xml xml-sitemap