2016-09-16 46 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 ** –