私は検索エンジン最適化にかなり慣れていません。しかし、サイトマップは SEO を大幅に改善できると聞いたことがあります。サイトマップ ファイルは xml 形式でなければならないことはわかっています。しかし、私のサイトのコンテンツは非常に動的です。そうは言っても、時間の経過とともにコンテンツがどのように変化したかを調べるために、DB にクエリを実行する必要があります。私のコードは次のとおりです。
<?php
require_once("functions.php");
connect();
// Query the DB to get the past season MLB teams
$query = mysql_query("SELECT * FROM past_season_team_articles") or die(mysql_error());
$count = mysql_num_rows($query);
$i = 0;
while($row = mysql_fetch_assoc($query))
{
$team[$i] = $row['team'];
$year[$i] = $row['year'];
$i++;
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php
// Loop thru the array and echo out the MLB teams
for($i=0;$i<$count;$i++)
{
?>
<url>
<loc>http://www.sportannica.com/teams.php?team=<?php echo $team[$i]; ?>&year=<? php echo $year[$i]; ?></loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<?php
}
?>
</urlset>