简体   繁体   English

查询数据库并返回结果

[英]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. 我已经建立了一个网站,这个网站是多语言的,它是用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 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. 在数据库中,我设法找到每个类别的表和行,我希望能够以另一种语言访问它,每个语言都有唯一的ID。

I know I have to grab the ID from the database of each category and return it to my PHP script. 我知道我必须从每个类别的数据库中获取ID并将其返回给我的PHP脚本。

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. 我不知道如何查询我的数据库,我也不支持如何修改php以便以其他语言打印。

Thanks 谢谢

Please refer to the Wordpress documentation, the "Codex" : 请参考Wordpress文档“ 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: 来自文档的WP_Query示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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