/*
Plugin Name: Google News Sitemap
Plugin URI: http://www.southcoastwebsites.co.uk/wordpress/
Version: v1.5
Author: Chris Jinks
Description: Basic XML sitemap generator for submission to Google News
Installation:
==============================================================================
1. Upload `google-news-sitemap-generator` directory to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Move the file "google-news-sitemap.xml" into your blog root directory and CHMOD to 777 so it is writable
4. Save/publish/delete a post to generate the sitemap
Release History:
==============================================================================
2008-08-04 v1.00 First release
2008-08-17 v1.1 Compatible with new Wordpress database taxonomy (>2.3)
2008-10-11 v1.2 Improved installation instructions, admin panel, general bug fixing
2009-07-27 v1.3 Exclude category options, scheduled posts now supported, UI improved.
2009-08-30 v1.3.1 Addition of XML version/encoding tag to beginning of sitemap
2009-11-11 v1.4 Update to new Google News Sitemap format
2010-03-13 v1.5 Update to new Google News Sitemap format
*/
/* Copyright 2008 Chris Jinks / David Stansbury
Original concept: David Stansbury - http://www.kb3kai.com/david_stansbury/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
function get_category_keywords($newsID)
{
global $wpdb;
//Check for new >2.3 Wordpress taxonomy
if (function_exists("get_taxonomy") && function_exists("get_terms"))
{
//Get categoy names
$categories = $wpdb->get_results("
SELECT $wpdb->terms.name FROM $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms
WHERE $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
AND $wpdb->term_relationships.object_id = $newsID
AND $wpdb->term_taxonomy.taxonomy = 'category'");
$i = 0;
$categoryKeywords = "";
foreach ($categories as $category)
{
if ($i>0){$categoryKeywords.= ", ";} //Comma seperator
$categoryKeywords.= $category->name; //ammed string
$i++;
}
//Get tags
$tags = $wpdb->get_results("
SELECT $wpdb->terms.name FROM $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms
WHERE $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
AND $wpdb->term_relationships.object_id = $newsID
AND $wpdb->term_taxonomy.taxonomy = 'post_tag'");
$i = 0;
$tagKeywords = "";
foreach ($tags as $tag)
{
if ($i>0){$tagKeywords.= ", ";} //Comma seperator
$tagKeywords.= $tag->name; //ammed string
$i++;
}
}
//Old Wordpress database <2.3
else
{
$categories = $wpdb->get_results("SELECT category_id FROM $wpdb->post2cat WHERE post_id=$newsID");
$i = 0;
$categoryKeywords = "";
foreach ($categories as $category)
{
if ($i>0){$categoryKeywords.= ", ";} //Comma seperator
$categoryKeywords.= get_catname($category->category_id); //ammed string
$i++;
}
}
if (get_option('googlenewssitemap_tagkeywords') == 'on')
{
if($tagKeywords!=NULL)
{
$categoryKeywords = $categoryKeywords.', '.$tagKeywords; //IF tags are included
}
}
return $categoryKeywords; //Return post category names as keywords
}
function write_google_news_sitemap()
{
global $wpdb;
// Fetch options from database
$permalink_structure = $wpdb->get_var("SELECT option_value FROM $wpdb->options
WHERE option_name='permalink_structure'");
$siteurl = $wpdb->get_var("SELECT option_value FROM $wpdb->options
WHERE option_name='siteurl'");
// Output XML header
// Begin urlset
$xmlOutput.= "
Accessing this file directly will not generate the sitemap.
The sitemap will be generated automatically when you save/pubish/delete a post from the standard Wordpress interface.
Instructions
1. Upload `google-news-sitemap-generator` directory to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Move the file "google-news-sitemap.xml" into your blog root directory and CHMOD to 777 so it is writable
4. Save/publish/delete a post to generate the sitemap