WordPress.org

Ready to get started?Download WordPress

Forums

Wpig Image gallery change help (5 posts)

  1. feale
    Member
    Posted 7 years ago #

    Just found the wpig http://www.thepenguinmafia.com/projects/wpig image gallery and it's brilliant. Simple, clean, easy to use, built in uploading and gallery management.

    Need one small bit of help. I'm no php programmer but I can get by customising scripts normally. I'm trying to change the image display on pages from tables to divs. The section is lines 274 - 314 and I've changed the code from this:

    //wpig_show_gallery() displays the gallery on the page, if the tag is set to do so.
    function wpig_show_gallery($content) {
    global $wpdb;
    $siteurl = get_option('siteurl');
    $gallery = '<table border=0><tr><th>Image Preview</th><th>Title & Description</th>';
    if(preg_match('|[gallery:([0-9]+)]|', $content, $matches) > 0) {
    $galleryid = $matches[1];
    $num_results = $wpdb->query("SELECT title, imgdesc, imgpath FROM wp_imagegallery WHERE imggallery=$galleryid ORDER BY id");
    $i = 0;
    while($i < $num_results) {
    $row = $wpdb->get_row("SELECT title, imgdesc, imgpath FROM wp_imagegallery WHERE imggallery=$galleryid ORDER BY id", ARRAY_A, $i);
    if(!file_exists(get_option('wpig_path') . 'gallery/thumbcache/' . $row['imgpath'])) {
    $srcim = @imagecreatefromjpeg($siteurl . '/wp-content/gallery/' . $row['imgpath']);
    $newwidth = 100;
    $newheight = 100 * (imagesy($srcim)/imagesx($srcim));
    $dstim = @imagecreatetruecolor($newwidth, $newheight);
    imagecopyresized($dstim, $srcim, 0, 0, 0, 0, $newwidth, $newheight, imagesx($srcim), imagesy($srcim));
    imagejpeg($dstim, get_option('wpig_path') . 'gallery/thumbcache/' . $row['imgpath']);
    }
    $gallery .= '<tr><td><a href="' . $siteurl . '/wp-content/gallery/' . $row['imgpath'] . '"><img src="' . $siteurl . '/wp-content/gallery/thumbcache/' . $row['imgpath'] . '" border=0></a></td><td><strong>' . $row['title'] . '</strong>' . $row['imgdesc'] . '</td></tr>';
    $i++;
    }
    $gallery .= '</table>';
    return preg_replace('|[gallery:([0-9]+)]|', $gallery, $content);
    } else {
    return $content;
    }
    }

    to this:

    //wpig_show_gallery() displays the gallery on the page, if the tag is set to do so.
    function wpig_show_gallery($content) {
    global $wpdb;
    $siteurl = get_option('siteurl');
    if(preg_match('|[gallery:([0-9]+)]|', $content, $matches) > 0) {
    $galleryid = $matches[1];
    $num_results = $wpdb->query("SELECT title, imgdesc, imgpath FROM wp_imagegallery WHERE imggallery=$galleryid ORDER BY id");
    $i = 0;
    while($i < $num_results) {
    $row = $wpdb->get_row("SELECT title, imgdesc, imgpath FROM wp_imagegallery WHERE imggallery=$galleryid ORDER BY id", ARRAY_A, $i);
    if(!file_exists(get_option('wpig_path') . 'gallery/thumbcache/' . $row['imgpath'])) {
    $srcim = @imagecreatefromjpeg($siteurl . '/wp-content/gallery/' . $row['imgpath']);
    $newwidth = 100;
    $newheight = 100 * (imagesy($srcim)/imagesx($srcim));
    $dstim = @imagecreatetruecolor($newwidth, $newheight);
    imagecopyresized($dstim, $srcim, 0, 0, 0, 0, $newwidth, $newheight, imagesx($srcim), imagesy($srcim));
    imagejpeg($dstim, get_option('wpig_path') . 'gallery/thumbcache/' . $row['imgpath']);
    }
    $gallery = '<div class=imgtbl><a href="' . $siteurl . '/wp-content/gallery/' . $row['imgpath'] . '"><img src="' . $siteurl . '/wp-content/gallery/thumbcache/' . $row['imgpath'] . '" border=0></a>' . $row['title'] . '' . $row['imgdesc'] . '</div>';
    $i++;
    }
    return preg_replace('|[gallery:([0-9]+)]|', $gallery, $content);
    } else {
    return $content;
    }
    }

    but it's only showing the last image/title/description from the gallery.

    Any ideas?

  2. Matt Farmer
    Member
    Posted 7 years ago #

    I see what you did.

    the line:

    $gallery = '<div class.....

    is supposed to be

    $gallery .= '<div class.....

    The dot by the equal mark means "append to". You were resetting the value of $gallery with each successive loop, which is why only the last image showed up.

    Making that change should fix your problem.

    Keep an eye out for a new version of WPIG though. I have a copy of a new version that includes the use of divs along with a whole handful of new features that I just haven't gotten around to implementing in my official distribution.

    M. Foxtrot
    The Penguin Mafia

  3. feale
    Member
    Posted 7 years ago #

    Looking forward to it Mr Foxtrot! Thanks for your help!

  4. yogaboat
    Member
    Posted 7 years ago #

    Fatal error: Call to undefined function: zip_open() in .../wpig.php on line 168

    This is line 168 from wpig.php:
    $zip_handle = zip_open($zip['tmp_name']);

    I'm getting the above error when creating a new gallery. I'm using WP 2.0.5, Almost Spring theme, and WPIG v1.4.0. I created the gallery directory and thumbcache subdirectory and CHMODed each to 665. The zip file I'm uploading is about 1.5MB.

    What can I do to move forward? This is the best gallery option I've found & I'd really like to use it!

  5. Matt Farmer
    Member
    Posted 7 years ago #

    Your having the same issue I was when I was first programming this latest version of WPIG - your web host has not enabled the zip functions in PHP. I need to rewrite the plugin to degrade more gracefully eventually.

    Send an email to your host and ask them to enable the zip functions in PHP. After they do that, everything should magically start working.

    Let me know how it goes!

    M. Foxtrot

Topic Closed

This topic has been closed to new replies.

About this Topic