xml.sitemap
Do anyone know how or where to put the xml sitemap for geekshop script? I uploaded it but Google says there is an error fetching it
Hello,
I am just following up on some of the old unanswered questions in case that someone comes across those in the future.
You can update the sitemap.xml
file to the public
directory. That way it will be accessible by Google.
Best,
Bobby
Hi,
How about sitemap.xml on Voyager? I'm adding many articles, but don't have any sitemap.xml ? And how to generate it ?
Thanks
Hi there,
You can just add a foreach and loop through all of your posts, for example:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://your-domain.com/</loc>
</url>
<url>
<loc>https://your-domain.com/blog</loc>
</url>
<url>
<loc>https://your-domain.com/about-me</loc>
</url>
<url>
<loc>https://your-domain.com/demos</loc>
</url>
@foreach($posts as $post)
<url>
<loc>https://your-domain.com/blog/{{ $post->slug }}</loc>
</url>
@endforeach
</urlset>
Your controller method would look something like this:
public function sitemap()
{
$posts = Post::where('visible', 1)->orderBy('updated_at', 'DESC')->get();
return response()->view('sitemap', compact('posts'))->header('Content-Type', 'text/xml');
}
And the route:
Route::get('/sitemap.xml', 'YourController@sitemap');
I have a similar example with RSS feed which you can take a look at here:
Create a simple RSS feed for Laravel
Hope that this helps!