2013-08-04 29 views
0

我試圖添加像Facebook的「狀態框」到我的網站,但只是與鏈接功能。 爲了清楚起見,我希望我的網站在有人共享鏈接時自動創建包含標題,說明和圖片(元標記)的帖子。 我使用了wp-web-scarper,但它只是擦除數據,不能使用此工具創建帖子。那麼有誰知道可以幫助我實現這一目標的客場或工具? 我只是在抓取網頁時依賴元標籤,所以它假設更簡單不行? 在此先感謝拉縮略圖和元數據爲wordpress

回答

0

在您FB.ui()功能添加的響應方法職位(無論是AJAX或突出部分正常的HTTP POST)回自己:

function(response) { 
      if (response && response.post_id) { 
       var form = document.createElement('form'); 
       form.setAttribute('method', 'POST'); 
       form.setAttribute('name', 'cpnfrm'); 
       var hiddenField = document.createElement('input'); 
       hiddenField.setAttribute('type', 'hidden'); 
       hiddenField.setAttribute('name', 'key'); 
       hiddenField.setAttribute('value', g); 
       form.appendChild(hiddenField); 
       document.body.appendChild(form); 
       form.submit(); 
      } 

其中G是某種價值(也許數組數據爲您的腳本)。從這個我想說檢查腳本中的有效職位,用它來創建一個帖子,rudamentiary例如:

if(!empty($_POST['key']){ 
    $post = array(
     'comment_status' => 'closed', 
     'post_name' => 'name', 
     'post_title' => 'title', 
     'post_content' => 'content' 
    ); 
    $inserted = wp_insert_post($post); 
    // add_post_meta($inserted, 'meta_key', 'meta_value'); 
} 

您可以使用作爲id wp_insert_post的響應。如果失敗,它應該返回false。 請注意,這不會一切準備好搖擺,你仍然需要抓住一些東西來檢測任何與js混淆的人,但它應該是一個起點。

希望這會有所幫助。