qTranslate support for the Google (XML) Sitemaps Generator WordPress Plugin

wordpress-logo-notext-rgb[1]

Some time ago, Qian Qin, the author of qTranslate, has published what should be modified on the Google (XML) Sitemaps Generator WordPress Plugin to make it support qTranslate.

However, this has never reached any of the releases of this plugin. (Qian Qin says he sent an e-mail to the author and I’ve done it myself, with no response).

So, I’m going to publish what should be modified on the plugin (for the ones who may want to do them themselves) and then, leave the link to download the modified version I prepared. I’ll be updating it for each new release.

Update: I’ve made some code corrections myself to include the different translations of the home page and not to include the entries not written in the default language (just include the written languages). The download and the code snippets have been updated to reflect the changes. If you wish more details, please go to the post of the update.

Update (2009-09-30): I’ve updated the naming of the plugin at the WordPress repository and the support for blogs without qTranslate installed. For releases before the 3.1.6.3, you may get notified for the original version updates (and not for this version supporting qTranslate), so I really recommend updating. If you wish more details, please go to the post of the update.

First, the changes… They are all made in the sitemap-core.php file…

Change 1

Original version:

		//Add the home page (WITH a slash!)
		if($this->GetOption("in_home")) {
			if('page' == get_option('show_on_front') && get_option('page_on_front')) {
				$pageOnFront = get_option('page_on_front');
				$p = get_page($pageOnFront);
				if($p) {
					$homePid = $p->ID;
					$this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql( ($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt)), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
				}
			} else {
				$this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql( get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
			}
		}

Modified version:

		//[NeoEGM] Moved here for home page support for different languages
		$useQTransLate = function_exists('qtrans_convertURL') && function_exists('qtrans_getAvailableLanguages');
		global $q_config;

		//Add the home page (WITH a slash!)
		if($this->GetOption("in_home")) {
			if('page' == get_option('show_on_front') && get_option('page_on_front')) {
				$pageOnFront = get_option('page_on_front');
				$p = get_page($pageOnFront);
				if($p) {
					$homePid = $p->ID;
					$this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql( ($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt)), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
					
					//[NeoEGM] Home page support for different languages
					if($useQTransLate)
						foreach($q_config['enabled_languages'] as $language)
							if($language != $q_config['default_language'])
								$this->AddUrl(qtrans_convertURL( trailingslashit($home), $language, true), $this->GetTimestampFromMySql( ($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt)), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
				}
			} else {
				$this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql( get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
				
				//[NeoEGM] Home page support for different languages
				if($useQTransLate)
					foreach($q_config['enabled_languages'] as $language)
						if($language != $q_config['default_language'])
							$this->AddUrl(qtrans_convertURL( trailingslashit($home), $language, true), $this->GetTimestampFromMySql( get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
			}
		}

Change 2

Original version:

$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet

Modified version:

//[NeoEGM] Line removed
//$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet

Change 3

Original version:

//Add it
$this->AddUrl($permalink,$this->GetTimestampFromMySql( ($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt)), ($isPage?$cf_pages:$cf_posts), $prio);

Modified version:

//Add it
//[NeoEGM] Add it only if the default language is defined, otherwise only add the defined languages
$QTranslateLanguages = qtrans_getAvailableLanguages($post->post_content);
if (in_array($q_config['default_language'], $QTranslateLanguages))
	$this->AddUrl($permalink, $this->GetTimestampFromMySql( ($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt)), ($isPage?$cf_pages:$cf_posts), $prio);

Change 4

Original version:

// Multilingual Support with qTranslate, thanks to Qian Qin
if ($useQTransLate) {
	global $q_config;
	foreach (qtrans_getEnabledLanguages($post->post_content) as $language) {
		if ($language != $q_config['default_language']) {
			$this->AddUrl(qtrans_convertURL($permalink, $language), $this->GetTimestampFromMySql( ($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt)), ($isPage ? $cf_pages : $cf_posts), $prio);
		}
	}
}

Modified version:

//Multilingual Support with qTranslate, thanks to Qian Qin
//[NeoEGM] Moved up the global variable scope line
if ($useQTransLate)
	foreach (qtrans_getAvailableLanguages($post->post_content) as $language)
		if ($language != $q_config['default_language'])
			$this->AddUrl(qtrans_convertURL($permalink, $language, true), $this->GetTimestampFromMySql( ($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt)), ($isPage ? $cf_pages : $cf_posts), $prio);

Download modified plugin version

Now, finally, the link…

Support appreciated!

All the content offered in this website is, except noted otherwise, of free nature. This means you can share it wherever you want if you do it freely and stating its source.

If it was useful for you and you’d like to contribute, you can make a donation or, at least, visit one of our advertisers of your choice; they are all around the site.

Incoming search terms for the article:



71 Responses to “qTranslate support for the Google (XML) Sitemaps Generator WordPress Plugin”


Leave a Reply to Eric Uned