Sitemap.xml with Drupal order by lastmod

If you have a Drupal 6 based site, you've probably installed the xmlsitemap module which works fairly well. A few days ago I reviewd mine and I saw that links were generated with no particular order, so I decided that it is good to show them ordered by lastmod to get the latest post first.
To make this work you need to change the source code of the xmlsitemap module file: xmlsitemap.generate.inc
Do a backup first!

And just find the function:

$query = array(
    'SELECT'   => 'SELECT x.loc, x.lastmod, x.changefreq,  x.changecount, x.priority, x.language',
    'FROM'     => 'FROM {xmlsitemap} x',
    'WHERE'    => 'WHERE x.access = 1 AND x.status = 1',
    'ORDER BY' => 'ORDER BY x.language, x.loc',
  );


and change it to:

$query = array(
    'SELECT'   => 'SELECT x.loc, x.lastmod, x.changefreq, x.changecount, x.priority, x.language',
    'FROM'     => 'FROM {xmlsitemap} x',
    'WHERE'    => 'WHERE x.access = 1 AND x.status = 1',
    'ORDER BY' => 'ORDER BY x.lastmod DESC',
  );



I know that it is not recommended to edit Drupal source code directly but the line in red did the trick! And now my sitemap.xml file is in descendant order showing the latest posts first.

Comments

Post a Comment

Your opinion is very appreciated, thank you!

Popular posts from this blog

Repair Dolce Gusto Circolo Leaking Problem

Root Nook Simple Touch with updated NookManager

How to Change the Gear Shift Knob of the Peugeot 306