WordPress.org

Support

Support » Plugins and Hacks » [NextGen Gallery] Exclude gallery when displaying random images

[NextGen Gallery] Exclude gallery when displaying random images

  • Hi everybody,

    I like to display random images of my galleries. I use this code and it works fine:

    [random max=7]

    But now I like to exclude a gallery. And I have no idea how I could do this. I searched the web and just found this code:

    http://www.vuthy.com/blog/2008/11/16/nextgen-gallery-random-photos-from-a-specific-gallery/

    This code works but I can’t change the layout of the displayed images. I need this HTML output:

    <div class="imageElement">
    
    		<h2><?php echo $image->alttext ?></h2>
    		<p></p>
    		<a href="#" title="" class="open"></a>
    		<img src="<?php echo $image->imageURL ?>" alt="<?php echo $image->alttext ?>" class="full" width="980" height="450" />
    		<img src="<?php echo $image->thumbnailURL ?>" alt="<?php echo $image->alttext ?>" class="thumbnail" />
    
    	</div>

    Does anybody has an idea? Thank you!

    Greetings from Germany,
    Raisis

Viewing 2 replies - 1 through 2 (of 2 total)
  • hey, mir scheint wir haben das gleiche problem. 🙂

    http://wordpress.org/support/topic/plugin-nextgen-gallery-random-and-recent-with-exclude-gallery

    wenn ich das so hinbekomme wie ich momentan denke lass ich es dich wissen. würd mich freuen auch deine versuche/ergebnisse hier zu sehen falls du erfolg hast.

    viele grüße

    Done!

    example: [random max=12 template=”random” exclude=”2″]

    /wp-content/plugins/nextgen-gallery/nggfunctions.php

    function nggShowRandomRecent($type, $maxImages, $template = '',$galleryId, $exclude) {
    
        // $_GET from wp_query
        $pid    = get_query_var('pid');
        $pageid = get_query_var('pageid');
    
        // get now the recent or random images
        switch ($type) {
            case 'random':
                $picturelist = nggdb::get_random_images($maxImages, $galleryId, $exclude);
                break;
            case 'id':
                $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
                break;
            case 'date':
                $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date');
                break;
            case 'sort':
                $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort');
                break;
            default:
                // default is by pid
                $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
        }
    
        // look for ImageBrowser if we have a $_GET('pid')
        if ( $pageid == get_the_ID() || !is_home() )
            if (!empty( $pid ))  {
                $out = nggCreateImageBrowser( $picturelist );
                return $out;
            }
    
        // go on if not empty
        if ( empty($picturelist) )
            return;
    
        // show gallery
        if ( is_array($picturelist) )
            $out = nggCreateGallery($picturelist, false, $template);
    
        $out = apply_filters('ngg_show_images_content', $out, $picturelist);
    
        return $out;
    }

    /wp-content/plugins/nextgen-gallery/lib/shortcodes.php

    function show_random( $atts ) {
    
            extract(shortcode_atts(array(
                'max'       => '',
                'template'  => '',
                'id'        => 0,
    			'exclude'   => 2
            ), $atts));
    
            $out = nggShowRandomRecent('random', $max, $template, $id, $exclude);
    
            return $out;
        }
    
        function show_recent( $atts ) {
    
            extract(shortcode_atts(array(
                'max'       => '',
                'template'  => '',
                'id'        => 0,
                'mode'      => 'id',
    			'exclude'   => 0
            ), $atts));
    
            $out = nggShowRandomRecent($mode, $max, $template, $id, '');
    
            return $out;
    }

    /wp-content/plugins/nextgen-gallery/lib/ngg-db.php

    function get_random_images($number = 1, $galleryID = 0,$exclude) {
            global $wpdb;
    
            $number = (int) $number;
            $galleryID = (int) $galleryID;
            $images = array();
    
    		$exclude = explode(',',$exclude);
    
    		foreach ( $exclude as $ex_gid ) {
    
    			$ex_sql_out .= ' AND tt.galleryid != '.$ex_gid.' ';
    
    			}
    
            // Query database
            if ($galleryID == 0)
                $result = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 ".$ex_sql_out." ORDER by rand() limit $number");
            else
                $result = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = $galleryID AND tt.exclude != 1 ".$ex_sql_out." ORDER by rand() limit {$number}");
    
            // Return the object from the query result
            if ($result) {
                foreach ($result as $image) {
                    $images[] = new nggImage( $image );
                }
                return $images;
            } 
    
            return null;
    }

    Simply replace the three functions.
    Unfortunately it does not work with recent. But at random.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[NextGen Gallery] Exclude gallery when displaying random images’ is closed to new replies.