icamys / php-sitemap-generator

A simple PHP sitemap generator.
MIT License
168 stars 65 forks source link

Support multiple images for a single page. #41

Closed ilya-vaikutis closed 1 year ago

ilya-vaikutis commented 2 years ago

Hi,

As per Google specification for image sitemaps, it is possible to have multiple images (up to 1000) for a single page.

You may find the example below:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>http://example.com/sample1.html</loc>
    <image:image>
      <image:loc>http://example.com/image.jpg</image:loc>
    </image:image>
    <image:image>
      <image:loc>http://example.com/photo.jpg</image:loc>
    </image:image>
  </url>
  <url>
    <loc>http://example.com/sample2.html</loc>
    <image:image>
      <image:loc>http://example.com/picture.jpg</image:loc>
    </image:image>
  </url>
</urlset>

The current implementation assumes passing a single 'google_image' key into the extension parameter, not allowing to pass an array of multiple 'google_image' elements, making it impossible to have multiple images added for a single path.

The proposed solution would be, in addition to accepting a flattened array (preserving backward compatibility), to allow passing an array of multiple image/video elements. Please refer to example below:

$extensions = [
   ['google_image' => ['loc' => 'https://www.example.com/thumbs/1.jpg']],
   ['google_image' => ['loc' => 'https://www.example.com/thumbs/2.jpg']],
   ['google_image' => ['loc' => 'https://www.example.com/thumbs/3.jpg']]
];

Thanks, Ilya

jhernandis commented 2 years ago

+1

We also need that improvement. Thanks.

mofthedev commented 1 year ago

54 I changed the extension so it works with multiple images. $extensions['google_image'] should be an array of arrays.

icamys commented 1 year ago

Thanks to everyone who participated. I'm preparing the next version which will include this improvement. Cheers!