PHP code example of dionisiy13 / google-news-sitemap

1. Go to this page and download the library: Download dionisiy13/google-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/ */

    

dionisiy13 / google-news-sitemap example snippets

 php
$sitemap = new \Dionisiy\SitemapGoogle\Sitemap($pathToFile);
$siteName = "example.com";
foreach ($posts as $item) {
    $sitemap->setGenres("Blog");
    $sitemap->setKeywords($item['tags']);
    $sitemap->setLanguage("en");
    $sitemap->setLoc($item['url']);
    $sitemap->setName($siteName);
    $sitemap->setPublicationDate($item['publishAt']->getTimestamp());
    $sitemap->setTitle($item['title']);
    $sitemap->setImages($item['images']);
    $sitemap->addItem();
}
$sitemap->write();