WordPress.org

Ready to get started?Download WordPress

Forums

WP Simple Galleries
Get First Image Of the Gallery (2 posts)

  1. raviac
    Member
    Posted 6 months ago #

    Hello,

    I am using WP-simple gallery plugin in One of my site.I just want to retrieve first image of the gallery.So can anyone suggest me how can i get
    first image of the gallery.

    Thanks,

    Ravi

    https://wordpress.org/plugins/wp-simple-galleries/

  2. euricovidal
    Member
    Posted 6 months ago #

    Hi,

    I also needed, I searching on web about it and not found anything, so I've read the Simple Gallery code for understand how I can this, and below the instructions:

    To get the images id use
    <?php $ids = get_meta_post ( $post->ID, 'wpsimplegallery_gallery'); ?>

    With the ids, you can get what you want, examples:

    To get the url (on media) of the first image
    <?php $url = wp_get_attachment_url ( $ids[0] ); ?>

    To get the generic thumb
    <?php the_attachment_link ( $ids[0] ); ?>

    To get the first 4 images

    <?php
    $images = array();
    for($i = 0; $i < 4; $i++) {
      $images[$i] = wp_get_attachment_image_src ( $ids[$i], array(320,160) );
      // 320, 160 = width, height or name of your thumb
    }
    ?>

    Hope this helps, I you need I am available.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.