我正在制作一个动态站点地图,我想要的是一个应该不同的优先级。假设如果 URL 是新的,那么优先级应该是 0.6400,但如果 URL 是两个月前的,那么优先级应该是 0.5400。我是通过以下方式制作的
这是代码。请指导这是正确的方法,并且不会在将来产生问题吗?:-
<?php
header("Content-Type: application/xml; charset=utf-8");
echo '<!--?xml version="1.0" encoding="UTF-8"?-->'.PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;
while($row1=mysqli_fetch_array($result15)){
echo $row1['post_date'];
$Created_at= $row1['post_date'];
$d = DateTime::createFromFormat("Y-m-d",$Created_at);
$Created_at= $d->format("Y-m");
echo '<url>' . PHP_EOL;
echo '<loc>'.'https://www.domain.in/post/'.$row1["id"].'/'. str_replace(' ','-',trim(preg_replace('/&(?!#?[a-z0-9]+;)/', '&',$row1['slug']))).'</loc>' . PHP_EOL;
echo '<lastmod>'.date('c',time()).'</lastmod>' . PHP_EOL;
echo '<changefreq>daily</changefreq>' . PHP_EOL;
if($Created_at <= date('Y-m', strtotime(date('Y-m')." -2 month"))){
echo "<priority>0.5400</priority>".PHP_EOL;
} else{
echo "<priority>0.6400</priority>".PHP_EOL;
}
echo '</url>' . PHP_EOL;
}
echo '</urlset>' . PHP_EOL;
?>