PHP code example of cviebrock / laravel-news-sitemap

1. Go to this page and download the library: Download cviebrock/laravel-news-sitemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cviebrock / laravel-news-sitemap example snippets


'providers' => array(
    ...
    'Cviebrock\LaravelNewsSitemap\ServiceProvider',
);

// create a new sitemap instance
$sitemap = \App::make('Cviebrock\LaravelNewsSitemap\NewsSitemap');

// if it's not cached, then populate with entries
if (!$sitemap->isCached()) {

    foreach (Posts::all() as $post) {

		$extras = [];
		$images = [];

		foreach ($post->images as $image) {
			$images[] = [
			    'loc' => $image->url,
			    'caption' => $image->caption
            ];
		}

		$extras['keywords'] = $post->topics->lists('name');

		$this->sitemap->addEntry($post->url, $post->title, $post->published_at, $extras, $images);
	}

}

// returns an XML response
return $sitemap->render();
sh
php artisan config:publish cviebrock/laravel-news-sitemap