Tag description in two languages

Hi,

This might be a long shot, but I’m trying to see if anyone had the same problem and found a solution. I’m developing a WP 3.1 site for a client that relies on tag descriptions to display some info on the tag archive page. After I found out how this field would accept basic HTML, I stumbled upon another problem.

I use the qtranslate plugin to make sure the site is accessible in both Dutch and French, and this plugin allows me to translate the tag name in both languages, but not the tag description field, which means this is always displayed in one language. I’ve tried all kinds of shortcode provided by qtranslate, without any effect.

On the wordpress.org forums I found a solution to make sure the category descriptions (which had the same problem) would be displayed in the correct language using the shortcodes:


<?php
$category = get_the_category();
_e($category[0]->category_description, 'qtranslate');
?>

Sadly, this code doesn’t work for tags, so I tried adapting it for the tag description as such:


<?php
$posttags = get_the_tags();
_e($posttags[0]->tag_description, 'qtranslate');
?> 

Didn’t work. Does anyone know what is wrong with the above code? How come this works for categories and not for tags?

Thanks in advance for any offered help.

have you tried loosing _description off the tag part? So


<?php
 $posttags = get_the_tags();
 _e($posttags[0]->tag, 'qtranslate');
?>

I just tried that, shows up empty.

I am sorry, I am not sure then

No problem. I figured the tag_description part would be vital somehow, as it is the name of the “field” it needs to show. I don’t understand why this works for categories, but not for tags.

Maybe the theme doesn’t show it? I saw that note on the tag panel under admin. I also found: Function Reference/tag description « WordPress Codex, maybe you can hack that?

Thanks for the info. I’m familiar with the link you provided, I used that as a starting point. It does show my tag description, it just won’t recognize the qtranslate tags within this field (like it does for categories now).

I’m not sure how to hack this myself. I’m an absolute PHP/mySQL noob. I was thinking of maybe duplicating the description field and loading the second one in my template if FR is selected as a language, but I wouldn’t know where to start and this is not the most elegant solution in my opinion.

This appears to be more of a php problem than a content question. I’ll move the thread to php and see if you can find some more help over in their corner. :slight_smile:

Try this. :slight_smile:


<?php
$tags = get_the_tags();
if(0 < count($tags)){
  _e($tags[0]->description, 'qtranslate');
}else{
  echo 'No Tag(s)';
}

Thanks, but still no result. It shows the single_tag_title, and then a big white gap where the description should be… :frowning:

Does the description display without the _e function call?

Eg.


<?php
$tags = get_the_tags();
if(0 < count($tags)){
  echo $tags[0]->description;
}

No it doesn’t. Come to think of it, normally it is called as tag_description:


<?php tag_description (); ?>

try


_e(tag_description(),'qtranslate');

Hurray! That did the trick. :smiley:
Thanks a million guys!

Excellent news, good call Ryan. :slight_smile: