简体   繁体   中英

Query Database and Return the result

I am having a problem for a while now and I can´t seem to solve it on my own.

I have made a website, this website is multilingual and it was made in wordpress.

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.

http://madebysylvie.be/collection

In my database I manage to find the table and the rows of each category, I want to be able access it in a different language, each one has an unique ID.

I know I have to grab the ID from the database of each category and return it to my PHP script.

This is my code,

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

However I am not good enough to do this on my own, and I would be very happy if someone could help me out on this one.

I don't know how to query my database, and I am not shore how to modify the php in order to print it in the other languages.

Thanks

Please refer to the Wordpress documentation, the "Codex" :

But remember »Most of the time you can find the information you want without actually dealing with the class internals and globals variables. There are a whole bunch of functions that you can call from anywhere that will enable you to get the information you need.«

WP_Query example from the docs:

<?php

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM