0

我有一个由 Wordpress 中的模板制作的网站,我安装了一个翻译插件(qtranslate)。

http://madebysylvie.be/collection

在我的“相册”页面中,当我以默认语言(英语)对项目进行排序时,一切正常,但是如果我更改为另一种翻译(例如法语),则类别名称会更改并且标记的项目不会出现了。

这是执行该函数的 PHP 代码,

<ul class="filter_portfolio"> 

                <?php
                    // Get the taxonomy


                    $terms = get_terms('filter', $args);
                    // set a count to the amount of categories in our taxonomy
                    $count = count($terms); 
                    // set a count value to 0
                    $i=0;
                    // test if the count has any categories
                    if ($count > 0) {
                        // break each of the categories into individual elements
                        foreach ($terms as $term) {
                            // increase the count by 1
                            $i++;


                            // rewrite the output for each category

                            $term_list .= '<li class="segment-'.$i.'"><a href="javascript:void(0)" data-value="' . $term->slug . '">' . $term->name . '</a></li>';


                            // if count is equal to i then output blank
                            if ($count != $i)
                            {
                                $term_list .= '';
                            }
                            else 
                            {
                                $term_list .= '';
                            }
                        }
                        // print out each of the categories in our new format
                        echo $term_list;

                    }
                ?>

            </ul>

我想更改此代码块以识别翻译版本中的标签。我知道触发器是 ("data-value") 参数。

下面的代码让我翻译默认语言的分类法,

function qtranslate_edit_taxonomies(){
$args=array(
  'public' => true ,
  '_builtin' => false
);
$output = 'object'; // or objects
$operator = 'and'; // 'and' or 'or'

$taxonomies = get_taxonomies($args,$output,$operator); 

if  ($taxonomies) {
 foreach ($taxonomies  as $taxonomy ) {
     add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
     add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');        

 }
 }

}
add_action('admin_init', 'qtranslate_edit_taxonomies');
?>

非常感谢您的帮助!

4

1 回答 1

0

我怀疑您使用类别名称来过滤您的数据库记录。因此,在您的数据库中只有“englsh”名称,当您“翻译”它时,您的脚本无法正常工作,因为它使用新的“法语”名称。

您可以在执行查询之前尝试将类别名称转换为英文吗?


编辑
我实际上认为是让您找到一种将两个变量传递给您的 php 脚本的方法。任何适合您的需求。
例如,一些可能的情况是:
- 英语类别 + 语言 (fr) = 根据您选择的语言查询数据库并返回正确的结果(基于英语工作思想)
- 类别 id + 语言 (fr) = 与上述相同但更通用,因为您使用 id 从表中获取数据。

我猜你必须改变你的 html 和你的 php 脚本(一个传递正确的数据,另一个返回正确的格式)。

于 2013-09-09T07:53:30.300 回答