我在https://laravel-news.com/laravel-sitemap
的帮助下撰写了一个站点地图这是我的索引:
public function siteMap( )
{
$news=News::orderBy('time','desc')->where('time','<',time())->where('showview',1)->first();
$categories = Cat::orderBy('id' , 'desc')->first();
$games = Game::orderBy('id' , 'desc')->first();
$genres = Genre::orderBy('id' , 'desc')->first();
$movies = Movie::orderBy('id' , 'desc')->first();
$platforms = Platform::orderBy('id' , 'desc')->first();
return response()->view('siteMap.siteMap', [
'news' => $news,
'categories' => $categories,
'games' => $games,
'genres' => $genres,
'movies' => $movies,
'platforms' => $platforms
])->header('Content-Type', 'text/xml');
}
和我的刀片:
<?php
echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
{{-- site map for posts --}}
<sitemap>
<loc> //url /{{ $news->id }}/{{ $news->title }}</loc>
<lastmod>{{ date('c',$news->time) }}</lastmod>
</sitemap>
{{-- sitemap for categories --}}
<sitemap>
<loc>//url/{{ $categories->id }}/{{ $categories->name }}</loc>
<lastmod>{{ date('c', $categories->time) }}</lastmod>
</sitemap>
{{-- sitemap for games profile --}}
<sitemap>
<loc>//url/profiles/games/{{ $games->id }}/{{ $games->name }}</loc>
<lastmod>{{ date('c', (integer) $games->time) }}</lastmod>
</sitemap>
{{-- sitemap for genres profile --}}
<sitemap>
<loc>//url/{{ $genres->id }}/{{ $genres->name }}</loc>
<lastmod>{{ date('c', $genres->time) }}</lastmod>
</sitemap>
{{-- sitemap for movie profile --}}
<sitemap>
<loc>//url/{{ $movies->id }}/{{ $movies->name }}</loc>
<lastmod>{{ date('c', (integer) $movies->time) }}</lastmod>
</sitemap>
{{-- sitemap for platforms profile --}}
<sitemap>
<loc>//url/{{ $platforms->id }}/{{ $platforms->name }}</loc>
<lastmod>{{ date('c', (integer) $platforms->time) }}</lastmod>
</sitemap>
在主机上传并使用谷歌网站管理员后,我得到以下错误:
您的站点地图似乎是一个HTML页面。请改用支持的站点地图格式。
感谢您的帮助!