/*
Plugin Name: Simple Google Sitemap XML
Version: 1.4.0
Plugin URI: http://itx-technologies.com/blog/simple-google-sitemap-xml-for-wordpress
Description: Generates a valid Google XML sitemap with a very simple admin interface
Author: iTx Technologies
Author URI: http://itx-technologies.com/
*/
if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?");
//Pre-2.6 compatibility
if ( ! defined( 'WP_CONTENT_URL' ) )
define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( ! defined( 'WP_CONTENT_DIR' ) )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( ! defined( 'WP_PLUGIN_URL' ) )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( ! defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
/*
Genarates the actual XML sitemap file on the server
*/
function gsxml_generate_xmlsitemap() {
$filename = "sitemap.xml";
if (get_option('gsxml_store') == "1") { $file_handler = fopen(WP_PLUGIN_DIR.'/simple-google-sitemap-xml/'.$filename, "w+"); }
elseif (get_option('gsxml_store') == "2") { $file_handler = fopen(ABSPATH.$filename, "w+"); }
else { $file_handler = fopen(WP_PLUGIN_DIR.'/simple-google-sitemap-xml/'.$filename, "w+"); }
if (!$file_handler) {
die;
}
else {
$content = gsxml_get_content();
fwrite($file_handler, $content);
fclose($file_handler);
}
}
/*
Gets the content of the database and formats it to form valid XML
*/
function gsxml_get_content() {
global $wpdb;
/* Setting default values for the settings */
if (get_option('gsxml_hp')) { $home_p = get_option('gsxml_hp'); } else { $home_p = 0.5;}
if (get_option('gsxml_hf')) { $home_f = get_option('gsxml_hf'); } else { $home_f = 'weekly';}
if (get_option('gsxml_gp')) { $other_p = get_option('gsxml_gp'); } else { $other_p = 0.5;}
if (get_option('gsxml_gf')) { $other_f = get_option('gsxml_gf'); } else { $other_f = 'weekly';}
if (get_option('gsxml_pri_freq')) { $gsxml_pri_freq = get_option('gsxml_pri_freq');} else { $gsxml_pri_freq = "Disable"; }
if (!get_option('gsxml_cat')) { $gsxml_cat = 'NotInclude';} else { $gsxml_cat = get_option('gsxml_cat'); }
if (!get_option('gsxml_tag')) { $gsxml_tag = 'NotInclude';} else { $gsxml_tag = get_option('gsxml_tag'); }
$xmlcontent = ''."\n";
$xmlcontent .= ''."\n";
$xmlcontent .= "
".get_option( 'siteurl' )."/
".date('Y-m-d')." ";
// verify that priority + change frequency have been enabled
if ($gsxml_pri_freq == 'Enable') {
$xmlcontent .= "".$home_f."
".$home_p." ";
}
$xmlcontent .= " \n";
// Query for the posts
$table_name = $wpdb->prefix . "posts";
$query = "SELECT year(post_modified) AS y, month(post_modified) AS m, day(post_modified) AS d, ID,post_title, post_modified,post_name, post_type, post_parent FROM $table_name WHERE post_status = 'publish' AND (post_type = 'page' OR post_type = 'post') ORDER BY post_date DESC";
$myrows = $wpdb->get_results($query);
foreach ($myrows as $myrow) {
$permalink = utf8_encode($myrow->post_name);
$type = $myrow->post_type;
$date = $myrow->y."-";
if ($myrow->m < 10) {
$date .= "0".$myrow->m."-";
}
else {
$date .= $myrow->m."-";
}
if ($myrow->d < 10) {
$date .= "0".$myrow->d;
}
else {
$date .= $myrow->d;
}
$id = $myrow->ID;
//$url = get_option( 'siteurl' )."/?p=".$id;
$url = get_permalink($id);
$xmlcontent .= "
".$url."
".$date." ";
// verify that priority + change frequency have been enabled
if ($gsxml_pri_freq == 'Enable') {
$xmlcontent .= "".$other_f."
".$other_p." ";
}
$xmlcontent .= " \n";
}
// If categories have been enabled, include them in the XML
if ($gsxml_cat == 'Include') {
// Prepare the SQL query
$table_terms = $wpdb->prefix . "terms";
$table_taxonomy = $wpdb->prefix . "term_taxonomy";
$query = "SELECT $table_terms.term_id, $table_taxonomy.taxonomy FROM $table_terms, $table_taxonomy WHERE ($table_terms.term_id = $table_taxonomy.term_id AND $table_taxonomy.taxonomy = 'category') ";
$mycats = $wpdb->get_results($query);
// Output each category link with the date being when it
$date = date('Y-m-d');
foreach ($mycats as $mycat) {
$xmlcontent .= "
".get_category_link( $mycat->term_id )."
".$date." ";
// verify that priority + change frequency have been enabled
if ($gsxml_pri_freq == 'Enable') {
$xmlcontent .= "".$other_f."
".$other_p." ";
}
$xmlcontent .= " \n";
}
}
// If tags have been enabled, include them in the XML
if ($gsxml_tag == 'Include') {
// Prepare the SQL query
$table_terms = $wpdb->prefix . "terms";
$table_taxonomy = $wpdb->prefix . "term_taxonomy";
$query = "SELECT $table_terms.term_id, $table_taxonomy.taxonomy FROM $table_terms, $table_taxonomy WHERE ($table_terms.term_id = $table_taxonomy.term_id AND $table_taxonomy.taxonomy = 'post_tag') ";
$mytags = $wpdb->get_results($query);
// Output each category link with the date being when it
$date = date('Y-m-d');
foreach ($mytags as $mytag) {
$xmlcontent .= "
".get_tag_link( $mytag->term_id )."
".$date." ";
// verify that priority + change frequency have been enabled
if ($gsxml_pri_freq == 'Enable') {
$xmlcontent .= "".$other_f."
".$other_p." ";
}
$xmlcontent .= " \n";
}
}
// end of the XML sitemap
$xmlcontent .= ''."\n";
return $xmlcontent;
}
/*
Creates an admin link
*/
function gsxml_menu_link() {
if (function_exists('add_options_page')) {
$gsxml_page = add_options_page('Google Sitemap XML', 'Google Sitemap XML', 'administrator', basename(__FILE__), 'gsxml_settings');
}
}
/*
Admin setting page
*/
function gsxml_settings() {
if (get_option('gsxml_store') == "1") { $path = WP_PLUGIN_URL.'/simple-google-sitemap-xml/sitemap.xml'; }
elseif (get_option('gsxml_store') == "2") { $path = get_option( 'siteurl' ).'/sitemap.xml'; }
else { $path = WP_PLUGIN_URL.'/simple-google-sitemap-xml/sitemap.xml'; }
?>
Google Sitemap XML
Your XML Sitemap
This is the absolute URL of your XML sitemap. You can copy/paste it in Google Webmaster Tools which greatly increases the speed at which Google indexes your website.
The XML sitemap is automatically regenerated when you publish or delete a new post/page.
/* Generate the sitemap once the plugin is saved */
gsxml_generate_xmlsitemap();
}
/*
Paypal donate button
*/
function gsxml_paypal_donate() {
echo '';
}
if ( is_admin() ){
add_action('admin_menu', 'gsxml_menu_link');
}
function activate_gsxml () {
gsxml_generate_xmlsitemap();
}
//register_activation_hook(WP_PLUGIN_DIR.'/simple-google-sitemap-xml/simple-google-sitemap-xml.php', 'generate_xmlsitemap');
register_activation_hook(WP_PLUGIN_DIR.'/simple-google-sitemap-xml/simple-google-sitemap-xml.php','activate_gsxml');
add_action ( 'activate_plugin', 'gsxml_generate_xmlsitemap' );
add_action ( 'publish_post', 'gsxml_generate_xmlsitemap' );
add_action ( 'publish_page', 'gsxml_generate_xmlsitemap' );
add_action ( 'trashed_post', 'gsxml_generate_xmlsitemap' );
?>
Storia e Storie » Firenze Informa
Storia e Storie
Postato il 16 marzo 2011
Per festeggiare il compleanno della nostra Italia, ripercorriamo attraverso le pagine di Firenze Informa di Luglio-Agosto 2009 la straordinaria storia del nostro inno nazionale, Fratelli d’Italia!
Leggi di più