You are here

function theme_xmlsitemap_node_view_news in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.module \theme_xmlsitemap_node_view_news()

Display the nodes of a view as a Google News sitemap.

File

xmlsitemap_node/xmlsitemap_node.module, line 324
Adds nodes to the sitemap.

Code

function theme_xmlsitemap_node_view_news($view, $nodes, $type) {
  drupal_set_header('Content-Type: text/xml; charset=utf-8');
  print '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n";
  print '  xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"' . "\n";
  print '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n";
  print '  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n";
  print '  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";
  foreach ($nodes as $node) {
    $lastmod = variable_get('xmlsitemap_node_count_comments', TRUE) ? max($node->changed, $node->last_comment_timestamp) : $node->changed;
    print '  <url>' . "\n";
    print '    <loc>' . xmlsitemap_url('node/' . $node->nid, $node->alias, NULL, NULL, TRUE) . '</loc>' . "\n";
    print '    <lastmod>' . gmdate('Y-m-d\\TH:i:s+00:00', $lastmod) . '</lastmod>' . "\n";
    print '    <changefreq>' . xmlsitemap_sitemap_frequency(xmlsitemap_node_frequency($node)) . '</changefreq>' . "\n";
    print '    <news:news>' . "\n";
    print '      <news:publication_date>' . gmdate('Y-m-d\\TH:i:s+00:00', $node->created) . '</news:publication_date>' . "\n";
    print '    </news:news>' . "\n";
    print '  </url>' . "\n";
  }
  print '</urlset>';
  drupal_page_footer();
  exit;
}