WordPress“ REST API” WPBackery Page Builder和Ionic

发布于 2025-02-09 05:12:26 字数 292 浏览 1 评论 0原文

我正在通过Ionic应用中的REST API构建WordPress网站的内容,但我有一个问题: “ VisualComposer”创建的内容看起来像:

”“在此处输入图像说明”

我如何提取内容以获取文本和图像,是否有可能?

I'm requesting Content from WordPress website built with wpbackery page builder by REST API in ionic app but i have a problem :
the Contents created by "VisualComposer" looks like this :

enter image description here

how can i extract the content to get the text and images only , is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断肠人 2025-02-16 05:12:26

您需要在WordPress侧写代码,function.php

可以通过将以下代码添加到function.php(将另一个键添加到响应中,称为htmlcontent),将以下代码添加到function.php中返回API的响应中,添加另一个键

add_action( 'rest_api_init', function () {
   register_rest_field('page', 'htmlcontent', array(
      'get_callback'    => 'page_do_shortcodes',
      'update_callback' => null,
      'schema'          => null,
   ));
});

function page_do_shortcodes( $object, $field_name, $request ) {
   WPBMap::addAllMappedShortcodes();
   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );
   return $output;
}

例如,您 重写从API返回的原始密钥,content键:(

注意:上面显示的代码唯一更改是传递给regession_rest_field的第二个参数功能

add_action( 'rest_api_init', function () {
   register_rest_field('page', 'content', array(
      'get_callback'    => 'page_do_shortcodes',
      'update_callback' => null,
      'schema'          => null,
   ));
});

function page_do_shortcodes( $object, $field_name, $request ) {
   WPBMap::addAllMappedShortcodes();
   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );
   return $output;
}

You need to write code on the WordPress side, function.php.

For example, you can add another key to the response that returns from the call to the API by adding the following code to function.php (adding another key to the response called htmlcontent):

add_action( 'rest_api_init', function () {
   register_rest_field('page', 'htmlcontent', array(
      'get_callback'    => 'page_do_shortcodes',
      'update_callback' => null,
      'schema'          => null,
   ));
});

function page_do_shortcodes( $object, $field_name, $request ) {
   WPBMap::addAllMappedShortcodes();
   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );
   return $output;
}

Alternatively, you can rewrite the original key that comes back from api, the content key :

(Note: The only change from the code shown above is the second parameter passed to the register_rest_field function)

add_action( 'rest_api_init', function () {
   register_rest_field('page', 'content', array(
      'get_callback'    => 'page_do_shortcodes',
      'update_callback' => null,
      'schema'          => null,
   ));
});

function page_do_shortcodes( $object, $field_name, $request ) {
   WPBMap::addAllMappedShortcodes();
   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );
   return $output;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文