WordPress.org

Forums

Multi Image Metabox
[resolved] Can't retrieve image on site (8 posts)

  1. cynexz
    Member
    Posted 2 years ago #

    Hello,

    I'm having some problems with this plugin.

    The plugin works fine in the back-end. I can add images, it saves them. It's all ok.

    The problem is I can't get the images to show on the site itself..

    The code I use is:

    <?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
    ?>

    It gives me an error on the line of the beginning of the array: [0].

    On all the other codes snippets of this plugin it also gives me an error on [0] of array:

    Warning: Illegal offset type in C:\xampp\htdocs\autotest\wp-content\themes\twentytwelve\single.php on line 39

    Can someone also explain me what the numbers mean after each array item?

    http://wordpress.org/extend/plugins/multi-image-metabox/

  2. Willy Bahuaud
    Member
    Plugin Author

    Posted 2 years ago #

    Hello,

    If you want to retrieve the IDs of the linked pictures, juste do something like :
    $all_my_ids = get_image_ids();
    $all_my_ids will now contain all the IDs of the images (and you can do what you want with this...)

    If you want to print these picts, you can also use get_images_scr() like that :

    foreach(get_images_src() as $k => $i){
    echo '<img src="'.$i[0].'" width="'.$i[1].'" height="'.$i[2].'" />';
    }

    ...and all linked files will be printed.

    Do I have answered correctly your questions ?

    Maybe the plugin documentation is too light :-/

  3. cynexz
    Member
    Posted 2 years ago #

    Thank you for your fast response.

    I am not really good at php so I did not fully understand you documentation.

    What I have found working was:

    <?php
    $args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID
    );
    $images = get_posts( $args );
    foreach($images as $image): ?>
    <a rel="lightbox" href="<?php echo wp_get_attachment_url($image->ID); ?>" title="<?php echo wp_specialchars( get_the_title($image->ID), 1 ) ?>"><?php echo wp_get_attachment_image($image->ID, 'medium' ); ?></a>
    <?php endforeach;
    ?>

    I found out that with this plugin, it just adds images as attachments. So I found this code to just show all the attachments.

    I love your plugin, and it works fine now. Thank you very much.

    Maybe you could update the documentation for the people that also had the same problem as me and do not know what to do.

    Keep up the great work ;)

  4. gerzok
    Member
    Posted 2 years ago #

    I had the same problem, but thanks to cynexz i could solve it =D

  5. Willy Bahuaud
    Member
    Plugin Author

    Posted 2 years ago #

    Hello,

    The cynexz solution doesn't do the same thing.
    He retrieve all picture which have been uploaded by the current post.

    But in my plugin, images are not always attached to the post.

    I prefer this :

    foreach(get_images_src() as $k => $i){
    echo '<img src="'.$i[0].'" width="'.$i[1].'" height="'.$i[2].'" />';
    }

    :-D

  6. creativemanner
    Member
    Posted 1 year ago #

    Could you please give a sample for get_multi_images_src() please!

  7. Willy Bahuaud
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, no problem :-)

    foreach(get_multi_images_src( 'thumbnail', 'large' ) as $k => $i){
    echo '<a href="'.$i[1][0].'" title="large size image"><img src="'.$i[0][0].'" width="'.$i[0][1].'" height="'.$i[0][2].'" /></a>';
    }

    You can also pass some parameter to the function, to include post thumbnail, or retrieve images of a specific post.

  8. creativemanner
    Member
    Posted 1 year ago #

    thanks Willy

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multi Image Metabox
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.