Site I'm working on has some very unique settings for determining when/where a story appears, so using views to create the sitemap makes life easy. I'll be using this as a guide
http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=74288

If you do not have odd requirements, I recommend using this module instead.
http://drupal.org/project/googlenews

Comments

mikeytown2’s picture

Create a new view
Style: XML data document
Root element name: urlset
Top-level child element name: url

Using Views Custom Field create 2 PHP code fields.
loc

echo url('node/' . $data->nid, array('absolute' => TRUE));

n:news

$node = mymodule_sitemap_views($data);
echo $node;
function mymodule_preprocess_views_views_xml_style_raw($vars) {
  $vars['xml'] = str_replace('<urlset>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"  xmlns:n="http://www.google.com/schemas/sitemap-news/0.9">', $vars['xml']);
}

function mymodule_sitemap_views($data) {
  global $language;
  static $nodes = array();
  $nid = $data->nid;

  // Is the node statically cached?
  if (!isset($nodes[$nid])) {
    // Retrieve node nid, type, language.
    $op = 'load';
    $node = db_fetch_object(db_query("SELECT nid, vid, title FROM {node} WHERE nid = %d", $nid));
    // Get taxonomy info
    if (module_exists('taxonomy')) {
      $node->taxonomy = taxonomy_node_get_terms($node);
    }
    // Set published date CCK field
    if (empty($node->field_pub_date)) {
      $node->field_pub_date[0] = array(
        'value' => $data->node_data_field_pub_date_field_pub_date_value,
        'timezone' => variable_get('date_default_timezone_name', 0),
        'timezone_db' => 'UTC',
        'date_type' => 'datestamp',
      );
    }
    $nodes[$nid] = $node;
  }

  // Select node
  $node = $nodes[$nid];
  // Get list of terms
  $keywords = array();
  foreach ($node->taxonomy as $term) {
    $keywords[] = $term->name;
  }
  // Generate output
  $output = '';
  $output .= '<n:publication>';
    $output .= '<n:name>' . variable_get('site_name', 'Drupal') . '</n:name>';
    $output .= '<n:language>' . check_plain($language->language) . '</n:language>';
  $output .= '</n:publication>';
  $output .= '<n:publication_date>' . date(DATE_W3C, $node->field_pub_date[0]['value']) . '</n:publication_date>';
  $output .= '<n:title>' . check_plain($node->title) . '</n:title>';
  $output .= '<n:keywords>' . implode(', ', $keywords) . '</n:keywords>';

  return $output;
}

This site has a published date CCK field that tells at what time the node hits the front page view and is thus available to see. Also uses domain access source so no duplicate content

Node: Type = News
Node: Published Yes
Date: Date (node) Content: Publish Date (field_pub_date) between now -2 days and now
Domain Source: Domain Source ID = Current Domain

fas’s picture

Thanks Mikey!

Just what I was looking for!

The example you put working perfectly.

What is not working is the part that replaces the "(urlset)" by "(urlset mln = "http://www.sitemaps.org/schemas/sitemap/0.9" xmlns: n = "http://www.google.com / schemas/sitemap-news/0.9 ">)"

The third PHP code you put this into a custom module.

But the part of, mymodule_preprocess_views_views_xml_style_raw, it seems not working.

Can you give me a hand?

Sorry for the bad English.

Greetings from Argentina!

mikeytown2’s picture

Theme functions require a clear cache in order to work. Try clearing your caches and give it another go.

fas’s picture

Thanks!!! Is working now!

Regards!

zeip’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Drupal 6 has been EOL for some years, closing all D6 issues.