2016-09-16 80 views
1

我正在开发一个离子应用程序,其中我有一个休息api从wordpress页面获取博客内容。我试图通过API获取视觉作曲页面,但我得到原始的HTML格式和CSS或缺少可视组件页面。我可以通过api获得完整的视觉作曲页面吗?或者是否有使用api的限制?如何通过休息api获取视觉作曲家页面

回答

2

我想你找到你的答案在这里:https://github.com/WP-API/WP-API/issues/2578

下面的例子是从上面的链接采取(谢谢你,bradmsmith!)

下面是一个例子如何在渲染VC简码一个帖子的内容:

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

function compasshb_do_shortcodes($object, $field_name, $request) 
{ 
    WPBMap::addAllMappedShortcodes(); // This does all the work 

    global $post; 
    $post = get_post ($object['id']); 
    $output['rendered'] = apply_filters('the_content', $post->post_content); 

    return $output; 
} 
+0

嗨,你能告诉我在哪里可以把这段代码?我是新来的wordpress – DD77

+1

** functions.php ** –