google-news.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?= '<'.'?'.'xml version="1.0" encoding="UTF-8"?>'."\n" ?>
  2. <?php if (null != $style) {
  3. echo '<'.'?'.'xml-stylesheet href="'.$style.'" type="text/xsl"?>'."\n";
  4. } ?>
  5. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  6. <?php foreach ($items as $item) : ?>
  7. <url>
  8. <loc><?= $item['loc'] ?></loc>
  9. <?php
  10. if ($item['lastmod'] !== null) {
  11. echo '<lastmod>'.date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])).'</lastmod>'."\n";
  12. }
  13. ?>
  14. <?php
  15. if (! empty($item['alternates'])) {
  16. foreach ($item['alternates'] as $alternate) {
  17. echo '<xhtml:link rel="alternate" media="'.$alternate['media'].'" href="'.$alternate['url'].'" />'."\n";
  18. }
  19. }
  20. ?>
  21. <news:news>
  22. <news:publication>
  23. <news:name><?= $item['googlenews']['sitename'] ?></news:name>
  24. <news:language><?= $item['googlenews']['language'] ?></news:language>
  25. </news:publication>
  26. <news:publication_date><?= date('Y-m-d\TH:i:sP', strtotime($item['googlenews']['publication_date'])) ?></news:publication_date>
  27. <news:title><?= $item['title'] ?></news:title>
  28. <?php
  29. if (isset($item['googlenews']['access'])) {
  30. echo "\t\t".'<news:access>'.$item['googlenews']['access'].'</news:access>'."\n";
  31. }
  32. if (isset($item['googlenews']['keywords'])) {
  33. echo "\t\t".'<news:keywords>'.implode(',', $item['googlenews']['keywords']).'</news:keywords>'."\n";
  34. }
  35. if (isset($item['googlenews']['genres'])) {
  36. echo "\t\t".'<news:genres>'.implode(',', $item['googlenews']['genres']).'</news:genres>'."\n";
  37. }
  38. if (isset($item['googlenews']['stock_tickers'])) {
  39. echo "\t\t".'<news:stock_tickers>'.implode(',', $item['googlenews']['stock_tickers']).'</news:stock_tickers>'."\n";
  40. }
  41. ?>
  42. </news:news>
  43. </url>
  44. <?php endforeach; ?>
  45. </urlset>