2012-10-28 39 views
0

由於Stackexchange的WordPress論壇幾乎沒有人填充,我以爲我會在這裏問同樣的問題,因爲這是我通常發佈的地方。用戶通過WordPress中的帖子將圖片添加到幻燈片中

原帖:https://wordpress.stackexchange.com/questions/70742/users-adding-images-to-a-slideshow-through-posts

我有一個頁面,在這裏我希望用戶能夠創建自己的帖子,這個令人費解的我用的插件WP User Frontend

每篇文章包含各種文本字段,包括描述,位置,聯繫信息,最後是精選圖片(縮略圖)。

現在,我想添加一項功能,使我的用戶可以將最多五張自選圖片添加到幻燈片中 - 用戶製作的每個帖子都應該包含幻燈片。我會怎麼做?

如果我可以讓WP用戶前端與已有的幻燈片插件一起工作(例如Meteor SlidesSlideshow?),我會認爲它可以工作?也許通過一個自定義PHP語句?

我試過這樣做了幾天。現在我轉向你,希望終於解決這個問題。

回答

0

爲了上傳圖片外到functions.php

function uploadImage($new_post){ 
$inc = 1;  
if ($_FILES) { 
    foreach ($_FILES as $file => $array) {   
     $newupload = insert_attachment($file,$new_post); 
     // $newupload returns the attachment id of the file that 
     // was just uploaded. Do whatever you want with that now. 
     $inc++; 
    } 
} 

} 

function insert_attachment($file_handler,$post_id) { 

// check to make sure its a successful upload 
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) return false; 

require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 
require_once(ABSPATH . "wp-admin" . '/includes/file.php'); 
require_once(ABSPATH . "wp-admin" . '/includes/media.php'); 

$attach_id = media_handle_upload($file_handler, $post_id); 
} 

粘貼這些代碼,並與新的帖子ID

uploadImage($the_post_id); 

調用uploadimage函數模板中只是投入五個載輸入形式和itll自動讀功能

+0

我沒有收到您的帖子通知 - 這就是爲什麼我回復這麼晚。我想在標準'single.php'模板中發佈'uploadImage($ the_post_id)',這意味着我希望自動選擇'$ the_post_id' - 你知道怎麼做嗎? –

+0

如果你想獲得single.php當前職位ID,那麼你可以這樣做:global $ post; uploadImage($後> ID); – loQ

+0

'<?php global $ post; uploadImage($後> ID); ?>沒有顯示帖子中的所有上傳圖片。圖像仍然顯示在<?php the_content(); ?>'。我現在順便使用插件'Post from Site',因爲'WP User Frontend'不能將超過1個圖像附加到它的前端形式。 –

相關問題