WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Multi Image Metabox

Add a multi-image metabox to your posts, pages and custom post types

Set concerned post types

Paste this into your theme's functions.php file :

<?php
    add_filter('images_cpt','my_image_cpt');
    function my_image_cpt(){
        $cpts = array('page','my_custom_post_type');
        return $cpts;
    }
?>

Set allowed number of picts

Paste this into your theme's functions.php file :

<?php
    add_filter('list_images','my_list_images');
    function my_list_images(){
        //I only need two pictures
        $picts = array(
            'image1' => '_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 :

  1. include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
  2. ID (integer) for targeting images linked to a specific post
<?php 
get_images_ids(true,id); 
// 2 accepted parameter : thumbnail (BOOLEAN), and id (to target a specific post)
// if thumbnail = true, join the id of the post thumbnail at the front of the returned array

//An exemple of output
array(
    [0]  => 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 :

  1. size (string) the size to return
  2. include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
  3. ID (integer) for targeting images linked to a specific post
<?php 
get_images_src('medium',false,id); //3 accepted parameter : the size (STRING) & thumbnail (BOOLEAN) & id (integer)

//An exemple of output
array(
    'image1' => 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 :

  1. size (string) the size to return
  2. size2 (string) another size to return
  3. include the thumbnail ? (boolean) if true include the thumbnail in the returned datas
  4. ID (integer) for targeting images linked to a specific post
<?php 
get_multi_images_src('medium','full',false,id); //4 accepted parameters : the 1st size (STRING) & the 2nd size (STRING) & thumbnail (BOOLEAN) & id (integer)

//An exemple of output
array(
    'image1' => 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

?>

Requires: 3.0 or higher
Compatible up to: 3.5.2
Last Updated: 2013-3-26
Downloads: 4,194

Ratings

5 stars
5 out of 5 stars

Support

0 of 1 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
1 person says it's broken.

100,1,1 100,1,1 100,1,1 100,2,2
100,2,2
0,1,0