22.07.2014

Picture sitemaps – a pain…


Picture sitemaps are quite important to get listed at search engines. But there are more question than solutions, unfortunately. The available scripts have either some primitive design using http calls, they are expensive or not working at all.

At the end, I was doing something on my own using the php sitemap-generator library at github. It has also some quirks, so I disabled at line #126

#return $this->sitemap_name."_".$offset;
return $this->sitemap_name;

and use my own numbering as the script consumed too much memory. Here is the code using that library

<?php
#ini_set('display_errors', 1);
#error_reporting(E_ALL);
#set_time_limit(300);
#ignore_user_abort(true);
#date_default_timezone_set('Europe/Berlin');

$t=date("Y-m-d\TH:i:s.000\Z");

include('sitemap-generator/sitemap.php');

$d3  = opendir('./dir/'); 
while (false !== ($filename = readdir($d3))) { $files3[] = $filename; }
  echo($dir.'<br/>');
  foreach ($files3 as $k => $item) {
    if (end(explode('.',$item)) == "jpg") {

      # page link
      $f='http://www.wjst.de/images/index.php?fn=central/'.$dir.'/'.$item;
      # picture link
      $g='http://www.wjst.de/images/cache/central/'.$dir.'/liquid'.$item;
      # I get my keywords and title from the exif data here

      $i++;
      $SitemapNode = new Sitemap('.', 'image'.intval($i/1000), 'image');
      $config = array(
        'type'   => 'url',
        'params' => array(
          'loc'   => $f,
          'image' => array(
            'loc' => $g,
            'caption' => 'keyword',
            'title' => 'title',
             'license'=> 'link'
          )
        )
      );
      $SitemapNode->add_node($config);

    }

  }

}
?>
<a href="core.xml">done</a>