XML sitemap add-on for sNews

XML sitemap add-on for sNews

Here is an add on for sNews CMS v1.7 to generate a valid XML sitemap for search engines to use. If you're not familiar with XML sitemaps, you should read up at sitemaps.org. Sitemaps are an extremely useful way for search engines to index all of your content.

The way this sitemap mod is set up, you can simply edit the variables in the script and drop it on your server and it should work. There is some optional extended functionality covered at the end of this article as well.

Set it up

To get started, download & extract the file;

sitemap_1.0.1.zip

Now edit the variables to match your site;

$server = 'localhost';
$dbuser = '';
$dbpass = '';
$dbname = '';
$dbprefix = '';
$site = 'http://www.mysite.com';

That's it! Now upload to your site, preferably in the root public_html directory. Now visit the page and you should see the XML sitemap generated from your articles, categories & pages.

Extending the sitemap mod

As I use this sitemap mod on my sNews sites, I have added a "last modified" field to my articles table, so that when I edit an article, the last modified time is reflected within the sitemap. Adding this functionality is quite easy. To start with, you need to add the field to your database, so open up PhPMyAdmin or whatever DB tool you use and add the column;

ALTER TABLE articles ADD last_mod datetime NULL;

Now you just need to edit your snews.php file to update the last_mod field when you edit your articles. Open your snews.php file, and within the function processing, around line 2951, find the following;

artorder = '$artorder'

Now replace it with this;

artorder = '$artorder',
last_mod = NOW()

Upload your edited snews.php file and now when you edit an article it should update that field and the sitemap.php add-on file will reflect the changes.

Notify the search engines

Don't forget to notify the search engines! Add your sitemap to:

And while you're at it, add the sitemap location to your robots.txt file;

Sitemap: http://www.mysite.com/sitemap.php

Tags

 

You might like

Comments


Hi! Thanks for the mod. One query, do we need to deactive existing sitemap which is created by default in snewscms, while trying to view sitemap.php, I'm getting the sitemap which snewscms creates by default.


My fault, tried just sitemap instead of sitemap.php, it works fine, if you wish kindly remove my comments as I can't edit them. :)


Hi Jonathan,

I'll leave them up, just so I can expand on this for others who may be confused by what this add-on does.

The HTML sitemap generated by sNews is an overview listing of pages & articles. While this is a handy overview for humans to use to navigate your site, it doesn't contain the same information as an XML sitemap.

An XML sitemap (such like this add-on produces) is just an easy machine-readable way to feed page information to the search engines, with detailed priorities, last edit dates, etc.

They work in conjuction, one doesn't replace the other.

Thanks!


Hi Matt,

It's good to see you're still developing on sNews (though this post is ½ year old).

I simply love most of the addons you have made, and use them alot when i set up sNews for clients etc.

So keep going mate and get some activity on your website again =)

Kind regards
Morten


Hi Matt;

AFAIK, a "sitemap.xml" file must reside on the site. Perhaps I am over-looking something but this mod does not create this file, but merely generates an HTML doc when "sitemap.php" is run. How does a web-crawler such as Google or Bing find this?


Hi cc,

Did you read the entire article? Check out the bottom section "Notify the search engines". This is a PHP file, but it outputs valid XML for the Search Engines to read.

In your robots.txt file add this line at the top

Sitemap: http://www.mysite.com/sitemap.php


You can also add sitemap files directly in Google Webmaster Tools, and Bing's tools as well.


Matt,

Any chance you can add code which gives the last-mod for pages, sub-categories, and categories?

I only ask because I compared this output to my normal sitemap files and it includes the last-mod for 'folders' as well.

I also changed the namespace to :

header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'; 
echo '<urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.... xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';


Any info on the last-mod would be great! Thanks for the great script!


Hi Steve,

I could take a look at it, categories and sub-cats should be based on the last article published. Easy enough to do. Pages should already be all set... I thought? Been a while since I've looked at the code obviously, hehe. :P


Hey, Matt. Just tried this and it works ok.
Just one issue though: if one is using dbprefixes, there's an error thrown in the generated xml:

<b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>.../sitemap.php</b> on line <b>105</b>


This invalidates registering one's sitemap.php in the webmaster tools.
While the error is indeed in line 105, the source is in line 103.
Just replace

$query = "SELECT id,seftitle FROM categories WHERE id='".$c[subcat]."'";


with

$query = "SELECT id,seftitle FROM ".$dbprefix."categories WHERE id='".$c[subcat]."'";


All I did was to add the ".$dbprefix." part.


Ah, i always forget that damn prefix! File updated.

Thanks Nicu.


Hi
Thanks for the code. I have about 150000 urls in my site: http://vasthurengan.com/pin_code/

Can you help me to split the site map ( each upto 40000 urls or so).
Thanks in advance
vasthurengan


Hi vasthurengan,

Are you looking to split by category, or simply in chunks of 40,000?


Hi,
Whichever possible- google supports up to 40000 urls i think. 40000 is ok for me and comfortable. Thanks.
vasthurengan


Should be able to break it up in chunks of 40000 with a loop.

I'll see if I can do this tomorrow.


Hi Matt
If the html site map and xml site map are split by category it is good. Pl help me. Thanks.


vasthurengan,

I've been playign around with it, I don't have a test site running at the moment, so I'm not sure if this will even work, but try saving this file as sitemap.php;

http://www.mdj.us/files/sitemap.phps

Then split them using the p variable, aka;

Sitemap: http://www.mysite.com/sitemap.php
Sitemap: http://www.mysite.com/sitemap.php?p=1
Sitemap: http://www.mysite.com/sitemap.php?p=2
Sitemap: http://www.mysite.com/sitemap.php?p=3
Sitemap: http://www.mysite.com/sitemap.php?p=4


Hi Matt
The error log shows this:
PHP Notice: Undefined index: p in ..../public_html/pin_code/sitemap.php on line 24


Hi Matt,
Any success in split sitemap? eagerly waiting for you.
thanks
vasthurengan


Hi Vasthurengan,

Thanks for the feedback. I will have to install an sNews CMS some time to really test this out. I'm not sure when I will have the free time, but I'll see what I can do.


Hi Matt,
Any chance of making it work to make chunks of 40000 urls?
I am eagerly waiting for your help.
Thanks in advance and sorry for bothering you again.
vasthurengan

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top