Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

pedro_dles on "PHP: Add translated tags to category list"

$
0
0

I have a website made from a template in WordPress, I've installed a translation plugin (qtranslate).

http://madebysylvie.be/collection

In my "photo album" page when I sort the items in the default language (english) everything works fine, however if I change to another translation (ex.french), the name of the category changes and the tagged items don't appear anymore.

Here is the PHP code that executes that function,

<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>

would like to change this block of code in order to identify the tags in the translated version. I know that the trigger is the ("data-value") parameter.

The following code let's me translate the taxonomies from the default language,

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');
?>

Thank for helping.


Viewing all articles
Browse latest Browse all 8245

Trending Articles