My, admittedly, temporary solution to generating google sitemaps. It only works for articles, nothing else yet... read on for my fix to that.
Because I am very new at geeklog, and hardly know any PHP, I cobbled together this procedure.
I tried using the automated sitemap creator tools... they don't seem to like GL and do not index. Using the google-supplied script is useless too, so...
My solution has a hundred ugly things about it, but it provides a starting point for the creation of a true sitemap solution by a real programmer...
First, create a static page:
Title: whatever you want, I named mine xmlsitemap
Add to Menu: leave unchecked
Label: whatever you want - it won't be used.
Page format: BLANK PAGE
ID: sitemap.xml
(I use the rewrite URL option... I thought this would be good, then I learned Google Sitemap wants the file on the ROOT of the website... we'll get to that later.)
This code refers to my website, www.realpanama.org, make the appropriate changes using your site name and table names. For some reason, if I use variables for site URL, etc., I get SQL errors so I resorted to using the actual table names. Somebody care to enlighten me?
The original code I "stole" from pigstye.net. Thanks to TomW who created it...
Pigstye.net My original intention was to create an HTML page as the first page (www.realpanama.org/index.html), because it is totally different from the rest of the site... but I still wanted to get a listing of stories and to feature the top 4 stories on the site. And because I had trouble getting a static page to do it... this came about.
Text Formatted Code
$result = DB_query("Select sid, title, unix_timestamp(date) AS day FROM gl_stories WHERE (date <= NOW()) AND (draft_flag = 0) ORDER BY date DESC");
$nrows = DB_numRows($result);
$retval .= '<?xml version="1.0" encoding="UTF-8"?>'. chr(13) . chr(10);
$retval .= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"'. chr(13) . chr(10);
$retval .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . chr(13) . chr(10);
$retval .= 'xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84'. chr(13) . chr(10);
$retval .= 'http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">' . chr(13) . chr(10);
$retval .= '<url>'. chr(13) . chr(10);
$retval .= '<loc>' . 'http://www.realpanama.org</loc>'. chr(13) . chr(10);
$retval .= '<lastmod>' . date('Y-m-d') . '</lastmod>'. chr(13) . chr(10);
$retval .= '<changefreq>daily</changefreq>'. chr(13) . chr(10);
$retval .= '<priority>1.0</priority>'. chr(13) . chr(10);
$retval .= '</url>'. chr(13) . chr(10);
for ($i = 1; $i <= $nrows; $i++) {
$A = DB_fetchArray($result);
$retval .= '<url>'. chr(13) . chr(10);
$retval .= '<loc>' . 'http://www.realpanama.org/article.php/' . $A['sid'] . '</loc>'. chr(13) . chr(10);
$retval .= '<lastmod>' . date('Y-m-d',$A['day']) . '</lastmod>'. chr(13) . chr(10);
$retval .= '<changefreq>weekly</changefreq>'. chr(13) . chr(10);
$retval .= '<priority>0.5</priority>'. chr(13) . chr(10);
$retval .= '</url>'. chr(13) . chr(10);
}
$retval .= '</urlset>'. chr(13) . chr(10);
return $retval;
Centerblock: leave unchecked.
In a block: leave unchecked.
Set to: EXECUTE PHP
Exit type: leave unchecked.
Save your static page.
Now, in my site I get the following static page:
sitemap.xmlI thought I was done, and was ready to submit to Google, when I realized Google requires that pages listed in the index are in the same folder or below to where the sitemap resides. Not good!
I lack the ability to change the URL, so I had to do a Server Side Include trick.
Create a blank file named "sitemap.shtml", and put in the following content (should work on most servers).
Text Formatted Code
<!--#include virtual="/staticpages/index.php/sitemap.xml" -->
(On firefox it looks ugly, but it looks OK on IE... go figure... probably something that I did wrong, but I am sure someone will point it out).
Google doesn't seem to care if you offer a file named "sitemap.shtml", and it accepted my offering.
BUT... if you really want it to be named something like "sitemap.xml", then you must modify your .htaccess file on your root directory and make it look like this:
Text Formatted Code
ErrorDocument 404 /siteindex.php
AddType text/x-server-parsed-html .html .htm .shtml .xml
(btw, the first line has nothing to do with this, it is my way of sending people that might type a wrong or dead address to the GL sitemap page)
That modified .htaccess file now allows for server parsing of html, htm, shtml and XML files... you see where I am going with this?
Rename your siteindex.shtml file to siteindex.xml and you are done.
Submit it to google sitemaps.
There, that should do it.
I have checked MY xml file with xml checkers and they all say the file checks out.
I am sorry I need to do this in such a roundabout way... I just don't know a way to get it to do this *cleanly*... perhaps some more knowledgeable people in this forum will review this and update it.
If I was to add other things, I would fool around with the SQL query that gives life to this thing, but for now, all I wanted or need indexed is the articles themselves and the main page.
You will notice the main page, www.realpanama.org itself would not be generated by the code. I hacked that by simply adding it manually. It is the first section of the code. I use the php date function to make sure it always says the day's date and gave it a priority of 1.0 because it is the most important page. Everything else is set to 0.5, but you make the call and change it to whatever suits you.
If it works for you, I'd appreciate you post about it on this thread. It is very much a work in progress. It needs several things like making sure bad characters don't get through, etc. I will add them, and when I have them working, I will update this thread.
If I wanted to do it cleanly I would:
1. make it a real php script.
2. use php to write out a file from the return value and put it wherever I wanted.
Someday...
Finally, this code is working on a GL 1.3.11. Have to add that "sr1" soon...
Thanks.
realpanama.org