如何绕过语言选择的 wordpress API 运气。WPML 是付费的,仅为此我找到了 API 更新。
问问题
263 次
1 回答
0
我已经在 wordpress 中建立了一个网站,以便广播一些新闻。我在语言选择方面遇到了问题,因为默认 API 不支持,而且 WPML 是付费插件。所以我使用 Polylang 来使用多语言。之后,将它们发送到服务器然后再发送到其他应用程序的问题出现了。我们(与后端开发人员)所做的如下:
- 创建页面模板(在子主题文件夹中使用 /* 模板名称:CustomPageEl */ 创建一个 php 文件)
- 之后,当您创建页面时,您可以选择此模板“CustomPageEl”。
- 创建 2 页,每种语言一个。
在那里调用 PHP 函数,其中包含我需要的信息。(我想创建下面的 JSON)
{“id”:835,“日期”:“2017-06-22T16:06:45”,“链接”:“”,“标题”:“”,“内容”:“”,“摘录”:“” "标签": [], "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
于 2017-06-30T10:06:38.803 回答