Hi! I'm trying to implement hook_xmlsitemap_links() but finding that the links are not being added to the sitemap.

My code is (with test data)

/**
 * Implements hook_xmlsitemap_links()
 */
function compare_xmlsitemap_links() {

    watchdog('compare', 'In hook xmlsitemap');
  $links = array();

  $links[] = array(
    'type' => 'compare',
    'id' => 1,
    'loc' => 'http://localhost/compare/?q=product/1234',
    'lastmod' => strtotime("now"),
    'changefreq' => 4600,
  );

  return $links;
    
}

The hook is being triggered because I've seen the watchdog entries. However, the link is not being added.

As a further point, whilst the links I am adding are valid, they are not nodes, users, or taxonomy terms. Is that significant (i.e. does xmlsitemap perform validation on what it gets given)?

Comments

dave reid’s picture

Status: Active » Fixed

The 1.x module API is *really* odd. You have to save the data to the {xmlsitemap} table yourself in hook_xmlsitemap_links(). The module doesn't care about the returned array of links. You can see this for yourself in the xmlsitemap_node_xmlsitemap_links() in xmlsitemap_node.module.

FYI if you're looking to implement APIs, I'd highly suggest looking into and using the 2.x version.

badzilla’s picture

ok - thanks for that. I had already looked at the module_invoke_all(xmlsitemap_links) call and figured the return value wasn't been captured but really needed some advice as to the correct way of doing it.

Being ruthlessly honest, using the API hook_xmlsitemap_links() in my module isn't going to buy me much. I'm better off writing to {xmlsitemap} directly in my business logic when I need to, since you are telling me that's what I need to do anyway.

Many thanks for taking the trouble to respond!

Anonymous’s picture

But really, you should look at 2.x series to see what is done there first. 1.x is soon to go away.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.