im-success

Nov 11th, 2018 01:43 PM

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

bobbyiliev

May 25th, 2022 01:07 AM

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

ngatsejacques

Jun 9th, 2022 06:23 AM

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

bobbyiliev

Jun 9th, 2022 06:54 AM

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!