WordPress多语插件Qtranslate使用方法

目录


中英文切换按钮的调用:

使用这段代码来调用中英文切换按钮到网站的任一位置:

<?php echo qtrans_generateLanguageSelectCode(‘both’); ?>

WP主题站点标题中英化:

1.将后台站点标题更改为:

⌈:zh⌋站点标题⌈:en⌋Sitename  //注:请将⌈⌋替换为[]

之所以要改段代码,是因为大部分标题不支持尖括号输出,尖括号极容易造成站点XSS。

2.修改主题header.php文件,查找

bloginfo( 'name' );

将其更改为

echo _e(apply_filters(' ', bloginfo( 'name' )));

WP主题自定义域中英化

我们往往会把网站的URL填入到一个自定义域,如后在模板中统一调用。这样可以简化我们编辑文章,撰写html的麻烦。由于我们一般在调用自定义域内容的时候代码为:
<?php echo get_post_meta(get_the_ID(), “price”, true);?>
参考之前标题中英化,可以将上述代码更改为:
<?php echo _e(apply_filters(‘ ‘, _(get_post_meta($post->ID, ‘price’, true)))); ?>

WP主题菜单栏中英化

我们的习惯会将首页放置在菜单栏中,一般情况下,我们会将首页做为一个自定义连接添加到菜单栏,此时出现的问题是:

名称可以使用⌈:zh⌋站点标题⌈:en⌋ (将⌈⌋替换为[])区分,但是链接怎么改都不行。

百般无奈只下,我只能手动将首页链接添加到网站主题模版。为了让页面自动判断中英为,可以使用如下代码:

<ul><li><a href="<?php bloginfo('url');?>"><?php _e("<!--:zh-->首页<!--:--><!--:en-->Home<!--:-->");?></a></li></ul>

WP主题图片/LOGO中英化

对于一些无法直接填写img代码,所以,只能考虑判断当前页面的语言属性,代码如下:

<?php if(qtrans_getLanguage()=='zh'): ?>
中文内容
<?php endif; ?>
<?php if(qtrans_getLanguage()=='en'): ?>
英文内容
<?php endif; ?>

Readers Comments (3)

  1. The fans of this game are invited to visit bingo site in order
    to discover a few of the first-rated new online plays.
    Some countries keep a watch over the casinos that operate there, and you
    should limit your play to the people specific places.
    The sort of hand maybe you have in poker can be a similar regardless of what form of poker you might be collaborating in.

    回复
  2. Hi there! Quick question that’s completely off topic. Do you know how to make your
    site mobile friendly? My web site looks weird when viewing from my iphone 4.
    I’m trying to find a theme or plugin that might be
    able to correct this problem. If you have any recommendations, please share.
    Thanks!

    回复
  3. Magnificent site. A lot of helpful information here.
    I’m sending it to a few friends ans also sharing in delicious.
    And naturally, thank you on your effort!

    回复

Leave a comment

Your email address will not be published.


*


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

calf-blog-top