
內容簡介
這個外掛新增了一個 metabox,允許在一篇文章中上傳和連結多張圖片。
圖片是透過 meta_value(和附件 ID)連結。它們可以使用拖放重新排序。
允許的圖片數量和相關的文章類型可以使用 hooks 覆寫。
外掛包括許多檢索已連結圖片的功能。
如需有關使用本外掛的更多信息,請參閱“其他注記”部分的連結。
設定相關文章類型
將以下代碼複製到主題的 functions.php 檔案中:
設定允許的圖片數量
將以下代碼複製到主題的 functions.php 檔案中:
‘_image1’,
‘image2’ => ‘_image2’,
);
return $picts;
}
?>
設定允許的圖片數量,取決於文章類型
將以下代碼複製到主題的 functions.php 檔案中:
add_filter(‘list_images’,’my_list_images’,10,2);
function my_list_images($list_images, $cpt){
global $typenow;
if($typenow == “my_custom_post_type” || $cpt == “my_custom_post_type”)
$picts = array(
‘image1’ => ‘_image1’,
‘image2’ => ‘_image2’,
‘image3’ => ‘_image3’,
);
else
$picts = array(
‘image1’ => ‘_image1’,
‘image2’ => ‘_image2’,
‘image3’ => ‘_image3’,
‘image4’ => ‘_image4’,
‘image5’ => ‘_image5’,
‘image6’ => ‘_image6’,
‘image7’ => ‘_image7’,
‘image8’ => ‘_image8’,
);
return $picts;
}
get_images_ids()
此功能必須在模板文件或任何函數中使用。
它返回連結附件的 ID 數組。
它有兩個參數,分别是:
是否包含縮略圖?(布林值)如果為 true,則在返回的數據中包含縮略圖
ID(整數),用於定位與特定文章相關聯的圖像
45,
‘image1’ => 5,
‘image2’ => 6,
‘image3’ => 12,
‘image6’ => 20,
‘image7’ => 15
);
//未填圖片未返回
?>
get_images_src()
此功能必須在模板文件或任何函數中使用。
它按順序返回關聯附件的 URI 和尺寸的數組。
它有三個參數,分別是:
要返回的大小(字符串)
是否包含縮略圖?(布林值)如果為 true,則在返回的數據中包含縮略圖
ID(整數),用於定位與特定文章相關聯的圖像
array(
[0] => ‘http://url_of_the_medium_pict.jpg’,
[1] => 340,
[2] => 200,
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
This plugin add a metabox which allox to upload and link multiple images to one post.
Pictures are linked by the way of meta_value (and attachments ID). They can be reordered using drag and drop.
Number of allowed pictures and concerned post types can be overited using hooks.
Plugin includes many functions to retrieve linked pictures.
For more information on using the plugin, refer to the section “Other Notes”.
Set concerned post types
Paste this into your theme’s functions.php file :
Set allowed number of picts
Paste this into your theme’s functions.php file :
‘_image1’,
‘image2’ => ‘_image2’,
);
return $picts;
}
?>
Set allowed number of picts, depending to the post_type
Paste this into your theme’s functions.php file :
add_filter(‘list_images’,’my_list_images’,10,2);
function my_list_images($list_images, $cpt){
global $typenow;
if($typenow == “my_custom_post_type” || $cpt == “my_custom_post_type”)
$picts = array(
‘image1’ => ‘_image1’,
‘image2’ => ‘_image2’,
‘image3’ => ‘_image3’,
);
else
$picts = array(
‘image1’ => ‘_image1’,
‘image2’ => ‘_image2’,
‘image3’ => ‘_image3’,
‘image4’ => ‘_image4’,
‘image5’ => ‘_image5’,
‘image6’ => ‘_image6’,
‘image7’ => ‘_image7’,
‘image8’ => ‘_image8’,
);
return $picts;
}
get_images_ids()
This function have to be used into a template file, or any function.
It return an array of the linked attachments’s ID.
It take two arguments whose are :
include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
ID (integer) for targeting images linked to a specific post
45,
‘image1’ => 5,
‘image2’ => 6,
‘image3’ => 12,
‘image6’ => 20,
‘image7’ => 15
);
//Empty pictures ar not returned
?>
get_images_src()
This function have to be used into a template file, or any function.
It return an array of URIs and dimension for the linked attachments’s, by order.
It take three agruments whose are :
size (string) the size to return
include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
ID (integer) for targeting images linked to a specific post
array(
[0] => ‘http://url_of_the_medium_pict.jpg’,
[1] => 340,
[2] => 200,
[3] => false //I’ve no idea what is it…
),
‘image2’ => array(
[0] => ‘http://url_of_the_medium_second_pict.jpg’,
[1] => 340,
[2] => 200,
[3] => false //I’ve no idea what is it…
)
);
?>
get_multi_images_src()
Same as get_image_src(), but return two sizes for all the pictures.
It take for agruments whose are :
size (string) the size to return
size2 (string) another size to return
include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
ID (integer) for targeting images linked to a specific post
array(
[0] => array(
[0] => ‘http://url_of_the_medium_pict.jpg’,
[1] => 340,
[2] => 200,
[3] => false //I’ve no idea what is it…
),
[1] => array(
[0] => ‘http://url_of_the_full_pict.jpg’,
[1] => 1020,
[2] => 600,
[3] => false //I’ve no idea what is it…
),
),
‘image2’ => array(
[0] => array(
[0] => ‘http://url_of_the_medium_second_pict.jpg’,
[1] => 340,
[2] => 200,
[3] => false //I’ve no idea what is it…
),
[1] => array(
[0] => ‘http://url_of_the_second_full_pict.jpg’,
[1] => 1020,
[2] => 600,
[3] => false //I’ve no idea what is it…
)
)
);
//Empty pictures ar not returned
?>
