內容簡介
我原本為客戶撰寫這個外掛,藉此讓企業徽標顯示在 WordPress 文章內⋯⋯你認為很簡單?那如果我們面對的是對於 WordPress 的「新增媒體」或「新增圖片」頁面毫不知情的使用者。對於大多數人而言,這些操作都非常複雜,因此 SB Uploader 就應運而生了。
這個外掛讓上傳圖片的動作可以在文章 / 頁面編輯器相同的頁面內完成,不需另外有獨立的上傳按鈕,只有像慣常的儲存 / 發佈文章的按鈕。這樣可確保圖片在文章 / 撰寫過程中就可以選擇,而無需等到文章 / 頁面發佈後才進行上傳。
這個外掛可讓你在任何 WordPress 物件中加入任何數量的圖片,包括文章、頁面、分類、標籤、自訂文章型別或自訂分類法。可選擇性設定 WordPress 的特色圖片,以充分利用使用此功能的佈景主題。它還允許提供後備圖片,以便在未上傳圖片時提供。每個圖片都會建立短碼,因此您可以在樣板 / 小工具結構中上傳圖片並使用產生的短碼。
每個上傳者都有後備功能,可讓您集中指定當某個物件沒有上傳圖片時,要放置哪個圖片的 URL。總是有些時候您不想讓特定頁面有圖片,因此我添加了「禁用後備」選項以便實現此目的。
我很確信現在已經涵蓋了全部基本需求......如果您想讓這個外掛以「任何」方式進行擴充,請務必告訴我。
整合說明
它的運作方式(文章 / 頁面 / 自訂文章型別)
在編輯頁面介面的右上角加入一個 metabox,裡面包含一個簡單的檔案選擇器和瀏覽按鈕。當使用者按下發佈 / 儲存按鈕時,檔案會上傳並將 URL 放入命名為插件設置頁面中的自訂欄位的物件內。
許多佈景主題都會使用「特色圖片」,因此此外掛可以輕鬆地設定它,而無需修改佈景主題。或者,如果您希望在佈景主題中更充分地使用它們,可使用以下代碼之一。請注意,這些是函數宣告本身。使用說明在它們之下:
function sbu_get_the_image($custom_field, $post_id=false, $url_only=false, $width=false, $height=false, $quality=100) {
global $sbu;
return $sbu->get_the_post_image($custom_field, $post_id, $url_only, $width, $height, $quality);
}
function sbu_the_image($custom_field, $post_id=false, $url_only=false, $width=false, $height=false, $quality=100) {
echo sbu_get_the_image($custom_field, $post_id, $url_only, $width, $height, $quality);
}
function sbu_get_the_image_resized($custom_field, $width=false, $height=false, $quality=100, $post_id=false) {
return sbu_get_the_image($custom_field, $post_id, false, $width, $height, $quality);
}
function sbu_the_image_resized($custom_field, $width=false, $height=false, $quality=100, $post_id=false) {
echo sbu_get_the_image_resized($custom_field, $width, $height, $quality, $post_id);
}
function sbu_get_the_category_image($custom_field, $post_id=false) {
global $sbu;
return $sbu->get_taxonomy_image($custom_field, $post_id);
}
以下代碼可從核心上傳者那裡抓取圖片,用於「特色圖片」功能。此方法會將多個版本的圖片調整大小並保存在系統中,就像通常使用 WP 上傳者一樣,但介面更簡單、更適合消費者使用。
<?php
function sbu_the_wp_image($image_size_name='full', $post_
外掛標籤
開發者團隊
原文外掛簡介
I originally wrote this for a client as a way to get company logos to appear inside WordPress posts… easy you say huh? What about if we were dealing with people who had no idea what to do when looking at the standard WordPress ‘Add Media’ or ‘Add Image’ page. It all seemed a bit too complicated for the average person so SB Uploader was born.
The idea of the plugin is that it means the act of uploading an image can be done on the same page as the Post/Page editor and there is no separate upload button, just the Save/Publish Post/Page button as normal. This ensures that as part of their blog post or copywriting process an image could be chosen before publishing.
This plugin lets you add as many images as you like to any WordPress object.. be it Posts, Pages, Categories, Tags, Custom Post Types or Custom Taxomonies. It optionally can set the WordPress Featured Image to take advantages of themes that use this feature. It also allows for a fallback image which will be provided in the event that an image was not uploaded. Shortcodes are created for each image so that you can upload images and use the resultant shortcode anywhere in your template/widget structure.
There is a fallback feature with each uploader to allow you to centrally specify the URL of an image to put in place when one is not uploaded to an object. There are always times when you don’t want an image on a specific page so I have added a ‘disable fallback’ option to facilitate this.
I’m pretty sure that’s all bases covered for now.. Do let me know if you want to see this plugin extended in ANY way.
Integration Instructions
How does it work (Posts/Pages/Custom Post Types)?
A metabox is added to the top right hand corner of the edit page interface with a simple file selector with browse button. When the user hits Publish/Save the file is uploaded and the URL put into an object custom field named per the settings page included with the plugin.
A lot of themes will make use of the Featured Image and as such this plugin can easily set this with no theme modification necessary. Alternatively if you wish to use them more fully within your theme you can use one of the following pieces of code. Note that these are the function declarations themselves. The usage instructions are below them:
function sbu_get_the_image($custom_field, $post_id=false, $url_only=false, $width=false, $height=false, $quality=100) {
global $sbu;
return $sbu->get_the_post_image($custom_field, $post_id, $url_only, $width, $height, $quality);
}
function sbu_the_image($custom_field, $post_id=false, $url_only=false, $width=false, $height=false, $quality=100) {
echo sbu_get_the_image($custom_field, $post_id, $url_only, $width, $height, $quality);
}
function sbu_get_the_image_resized($custom_field, $width=false, $height=false, $quality=100, $post_id=false) {
return sbu_get_the_image($custom_field, $post_id, false, $width, $height, $quality);
}
function sbu_the_image_resized($custom_field, $width=false, $height=false, $quality=100, $post_id=false) {
echo sbu_get_the_image_resized($custom_field, $width, $height, $quality, $post_id);
}
function sbu_get_the_category_image($custom_field, $post_id=false) {
global $sbu;
return $sbu->get_taxonomy_image($custom_field, $post_id);
}
The following code to grab images from the core uploader for the Featured Image functionality. This method resizes and saves multiple versions within the system as you would expect from the normal WP uploader but with a simpler, more customer friendly, interface.
get_image($image_size_name, $post_id);
}
?>
If the above doesn’t make sense then, in basic terms, you just need to put something like this in your theme:
or if you wish to resize an image to fit a slot use this:
This would output the image as 700×200. Both parameters are optional so if you wanted a proportional resize based on 700 pixels in width then use this:
Or the old fashioned direct method of retrieving the image.
if ($image = get_post_meta(get_the_ID(), 'post_image', true)) {
$image = '';
}
echo $image;
How does it work (Tags/Categories/Taxonomies)?
As above but the file upload boxes are added to the taxonomy edit pages instead. Just click browse, choose an image and save the taxonomy/tag/category and you’re done.
I would normally wrap the image variable in a div tag with a class or give the image itself a class so that I can restrict the size or float the image (or both?) using the stylesheet. It simply means that you can include that image inside a template if it exists. Of course you could use the resize function I have provided above to get that perfect sized image on your site.
Note
I would like to add that there are coffee/donation adverts in this plugin. I personally hate it when, on adding a new plugin, dashboard widgets, donate buttons and begging messages appear. This plugin is clutter free and support is always available via my site (best responses here) and the WP forums (slower responses but I will get back to you). Have fun!
More info at http://www.sean-barton.co.uk/sb-uploader/
