Close

Как добавить элемент в Sitemap.xml

Есть такой Sitemap код:

PHP код:


/** * Sitemap */ Route::get('sitemap.xml', function() { $sitemap ''$sitemap .= ' ';

// Main page

$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url>';

$sitemap .= '<loc>' Uri::full(Registry::get('posts_page')->slug '/') . '</loc>';

$sitemap .= '<priority>0.9</priority>';

$sitemap .= '<changefreq>weekly</changefreq>';

$sitemap .= '</url>'

$query Post::where('status''=''published')->sort(Base::table('posts.created'), 'desc');

foreach(
$query->get() as $article) {

        
$sitemap .= '<url>';

        
$sitemap .= '<loc>' Uri::full(Registry::get('posts_page')->slug '/' $article->slug) . '</loc>';

    
$sitemap .= '<lastmod>' date("Y-m-d"strtotime($article->created)) .'</lastmod>';

    
$sitemap .= '<changefreq>monthly</changefreq>';

    
$sitemap .= '<priority>0.8</priority>';

    
$sitemap .= '</url>';

}

$sitemap .= '</urlset>';

return Response::create($sitemap200, array('content-type' => 'application/xml'));

}); 




Как добавить элемент <?xml version="1.0" encoding="UTF-8"?> сразу после // Main page чтобы он был в самом верху файла?

Я пробовал $sitemap .= ‘<?xml version="1.0" encoding="UTF-8"?>’;
Получается такая ошибка: XML declaration allowed only at the start of the document

Источник

Добавить комментарий