• Hi all,

    I need to pick the first image in a nextgen gallery and set it as facebook sharing image, by using the id of that gallery. What should i do?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Iperdesign_IT

    (@iperdesign_it)

    I use this query to retrive the first image into the DB

    $sql =
    "SELECT g.path, p.filename\n"
    . "FROM wp_ngg_gallery g\n"
    . "INNER JOIN wp_ngg_pictures p\n"
    . "WHERE ( g.gid = ".trim(get_post_meta($post->ID, 'Galleria', true))." AND p.galleryid = ".trim(get_post_meta($post->ID, 'Galleria', true))." ) LIMIT 0, 1 ";

    For the moment i solved this problem, but if someone know better ways, i’ll be very happy ^^

    I’m having the same problem. Somehow Facebook doesn’t detect the first nextgen image as the primary thumbnail. Probably this has something to do with the fact that the generated image from Nextgen is too large, so the FB API jumps to the first thumbnail it finds (which is something entirely else).

    I also need to dynamicly set the og:image parameter, based on the first image from a Nextgen Gallery album. I tried using jQuery, but that’s not working. If I could just do: get_nextgen_firstimage($gid); or something it would be a breeze, but no luck so far.

    I’ll keep you posted Iperdesign_IT if I find a fitting solution.

    Don’t know if it helps, but I’m using the following function in functions.php to retrieve the image from nextgen and place it directly in the opengraph metatag (I get the correct nextgen ID from a custom field):

    <meta property="og:image" content="<?php echo getFacebookThumbFromNextgen(get_field('nextgen_code')); ?>" />

    In functions.php I have the following function:

    function getFacebookThumbFromNextgen($galleryID=false) {
    if (!$galleryID) {
    return "No gallery ID provided";
    } else {
    global $wpdb;
    $imageDetails = $wpdb->get_results("SELECT wp_ngg_gallery.path,wp_ngg_pictures.filename FROM wp_ngg_gallery, wp_ngg_pictures	WHERE wp_ngg_gallery.gid = {$galleryID}	AND wp_ngg_pictures.galleryid = wp_ngg_gallery.gid LIMIT 0, 1");
    return get_bloginfo("wpurl") . "/". $imageDetails[0]->path ."/". $imageDetails[0]->filename;
    }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: NextGEN Gallery] How to get images by Gallery ID’ is closed to new replies.