Q&A about xili-language plugin, release 1.1

xili-language latest release 1.1

improves function and theme tag «  xiliml_the_others_posts() »
(this template tag displays list of links of linked posts in other languages – by example in subtitle)

  1. to be used in multilingual category loop and
  2. by option (array) to return an array of linked posts in other languages (useful for CMS webmasters) (array of lang and id ) – the id is easily transformable in permalink with function get_permalink() when using this array.
    IMPORTANT : if this function was previously hooked for your theme, it works but you must review the hooking function of your functions.php to include new array option (see plugin code).
Where to install this template tag ?

In the single.php or category.php just under the title like here in theme of dev.xiligroup.
Example of code :

<h2><?php the_title(); ?></h2>
      			<div class="postsubtitleinfo">
					<small class="ltr"><?php if (class_exists('xili_language')) {
						echo the_xili_local_time('%B %d, %Y - %H:%M',strtotime(get_the_time('m/d/Y H:i')));
						} else {
	the_time(__('F jS, Y','xilidev'));} ?> - </small> - <small dir="ltr"><?php xiliml_the_other_posts($post->ID); 
 
	?></small>
For theme’s designer : what is new in the function «  xiliml_the_others_posts() »

Essentially, the feature permitting to use this tag inside loop containing posts in multiple languages. (not only in single.php).

For developer : what is new in the function «  xiliml_the_others_posts() »

In the past, this function as a template tag only displays a list of links to other posts in other language. Now, (for developer or webmaster), when setting the fourth param to « array », it returns an array of values. The key are the language slug and the value is the ID of the linked post.

print_r(xiliml_the_other_posts($post->ID,"","","array"))

will return this array (exemple of willkommen post here)

Array ( [ar_ar] => 625 [en_us] => 4 [fr_fr] => 1 [12] => de_de )

You can see that latest key is the ID of the post ID param passed to the function (to help further treatments).
Remember also that the id is easily transformable in permalink with function get_permalink() when using this array.

How to display flag instead language name ?

It is possible if you personnalize your theme by adding a hook and a function inside your functions.php.

the hook (note that since 1.1, the lastest param is 4 (instead 3):

add_filter('xiliml_the_other_posts','xiliml_infunc_the_other_posts',10,4); // 1.1 090917

a example of hooking function :

/*special flags in list*/
function xiliml_infunc_the_other_posts($post_ID, $before = "This post in", $separator = ", ", $type = "display") {
			$outputarr = array();
			$listlanguages = get_terms(TAXONAME, array('hide_empty' => false));
			$langpost = get_cur_language($post_ID); // to be used in multilingual loop since 1.1
			$post_lang = $langpost['lang'];
			foreach ($listlanguages as $language) {
				$otherpost = get_post_meta($post_ID, 'lang-'.$language->slug, true);
 
				if ($type == "display") {
					if ('' != $otherpost && $language->slug != $post_lang ) {
						$outputarr[] = "<a href='".get_permalink($otherpost)."' >".__($language->description,THEME_TEXTDOMAIN) ." <img src='".get_bloginfo('template_directory')."/images/flags/".$language->slug.".png' alt='' /></a>";
					}
				} elseif ($type == "array") { // here don't exclude cur lang
					if ('' != $otherpost)
						$outputarr[$language->slug] = $otherpost;
				}
			}
			if ($type == "display") {
				if (!empty($outputarr))
					$output =  (($before !="") ? __($before,THEME_TEXTDOMAIN)." " : "" ).implode ($separator, $outputarr);
				if ('' != $output) { echo $output;}	
			} elseif ($type == "array") {
				if (!empty($outputarr)) {
					$outputarr[$post_ID] = $post_lang; 
					// add a key with curid to give his lang (empty if undefined)
					return $outputarr;
				} else {
					return false;	
				}
			}	
 
}
If I need more infos, what to do ?

Use comments below or forum

M.
 
 

xili-language plugin: Other posts for webmasters
  1. xili-language plugin : release 2.1
  2. Q&A about xili-language plugin, release 1.1
  3. xili-language : hooks, filters, class and so on...
  4. From a theme with localization to a multilingual theme with xili-language : technical and general notes.
  5. xili-language - 1.4.1 - new libraries
  6. Xili-language toolbox in one table
  7. xili-language and the time
  8. xili-language : Affichage des dates et heures
 
 

Ce contenu a été publié dans xili-language, avec comme mot(s)-clé(s) , , , , . Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire