Wordpress API语言选择绕过

时间:2017-06-30 10:06:39

标签: wordpress api multilingual polylang

如何绕过wordpress API语言选择的运气。 WPML是应付的,只是因为我找到了API更新。

1 个答案:

答案 0 :(得分:0)

我在wordpress中建立了一个网站,以便播放一些新闻。我在语言选择方面遇到了问题,因为默认的API不支持它,而且WPML也是应付插件。 所以我使用Polylang来使用多种语言。 之后,问题发送到服务器,然后发送到其他APPs的问题出现了。 我们(与后端开发人员)的作用如下:

  • 创建页面模板(使用/ *模板名称:CustomPageEl * /)在子主题文件夹中创建一个php文件
  • 之后,当您创建页面时,您可以选择此模板" CustomPageEl"。
  • 创建2个页面,每种语言一个。
  • 在那里调用PHP函数我需要的信息。(我想创建下面的JSON)

    {" id":835," date":" 2017-06-22T16:06:45"," link": "","标题":"","内容":"","摘录& #34;:"" ,"标签":[]," featureImageLink":"" }

    <?php /* Template Name: CustomPageEl */
    query_posts('post_type=post&post_status=publish');      
    $index=0;
    $mainObj=array();
    
    if( have_posts()): 
        while( have_posts() ): the_post();
            $posttags = get_the_tags();
            $count=0;
            if ($posttags) {
                $index1=0;
                foreach($posttags as $tag) {
                    $alltags[$index1] = ($tag->name);
                    $index1=$index1+1;
                }
            }
            $imageurl=get_the_post_thumbnail();
            if (!function_exists('my_custom_function'))   {
                function my_custom_function($string, $start, $end){
                $string = ' ' . $string;
                $ini = strpos($string, $start);
                if ($ini == 0) return '';
                    $ini += strlen($start);
                    $len = strpos($string, $end, $ini) - $ini;
                    return substr($string, $ini, $len);
                }
            }
            $imageurl = my_custom_function($imageurl, 'src="', '" class=');
            $mainObj[$index]=array('id' =>get_the_ID(), 'date'=>get_the_date('c'),'link'=>get_permalink(),'title'=>get_the_title(),'content'=>str_replace('"','\'',get_the_content()),'excerpt'=>str_replace('"','\'',get_the_excerpt()),'tags'=>$alltags,'featureImageLink'=>$imageurl);
            $index=$index+1;
        endwhile;
        $finalObf = json_encode($mainObj);
        wp_send_json($finalObf);
       endif; 
     wp_reset_query();
    ?> 
    
  • 结果是,当您进入该页面时,您将获得一个带有帖子的JSON数组,其中包含该页面的语言。

为了选择wordpress的功能,请参阅以下链接。 https://codex.wordpress.org/Function_Reference