Support » Plugin: NextGEN Gallery - WordPress Gallery Plugin » [Plugin: NextGEN Gallery] NextGen Widget Pagination

  • Hello,

    I’ve been searching for a way to include pagination for the Widget side gallery. Currently I’ve got albums with > 6 images in them but have selected to only display 6 with the intention of browsing through them much the same as the normal Gallery.

    Has this been achieved yet? This plugin is fantastic I’m using it with widget logic to display separate galleries depending on the page and have included hyperlinks to pages using ngg_custom_fields.

    I’ve yet to try to code this myself but it looks like it may be the way to go.

    Any feedback or suggestions will be highly appreciated.

    Thanks in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    I’ve made quite a bit of progress on this, added an “all” button to the widget next to “recent” and “random” through widgets.php within the nextgen-gallery widgets folder. The following is the code for adding the button.

    <label for="<?php echo $this->get_field_id('type'); ?>_all">
    <input id="<?php echo $this->get_field_id('type'); ?>_all" name="<?php echo $this->get_field_name('type'); ?>" type="radio" value="all" <?php checked("all", $instance['type']); ?> /> <?php _e('all','nggallery'); ?> </label>

    Next I copied the section of code (further down in widgets.php) which obtains the Image list through a Select statement modifying it to obtain all (without a limit). I placed a filter before the loop to display images to determine if ‘all’ type was selected.Used the values which the user selects to determine how many images per page (mine is 6 in my previous post) and used these values in array_slice to get a page by page snippet of images. My pagination links identify the correct navigation which is confirmed when I click on them which then puts that value in the address bar… eg

    With this nothing updates, I think the function I placed it in only gets called once despite being refreshed (its an included file). I manually changed the pagenum variable and reloaded the page which worked perfectly, just needed it to update by clicking on the >> pagination hyperlink. Below is the Code for the SQL query(immediately after the other statements) and filtering (before the foreach(Imagelist as Image).

    if ( $instance['type'] == 'random' )
    			$imageList = $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 $exclude_list ORDER by rand() limit {$items}");
    		elseif ( $instance['type'] == 'recent added')
    			$imageList = $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 $exclude_list ORDER by pid DESC limit 0,$items");
                            // Custom code, for other type of 'all'
                            $imageList = $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 $exclude_list");
    <----- code in between not copied to this post ---->
    		if (is_array($imageList)){    
                                   //Custom code for displaying images with pagination
                                   if ($instance['type']=='all') {
                                      if(!(isset($pagenum))) {
                                         $startimage = $pagenum - 2 + $instance['items'];
                                      } else {
                                         $startimage = $pagenum - 1;
                                    $imageCount = count($imageList);
                                    $totalpages = ceil($imageCount/$instance['items']);
                                    $DisplayArray = array_slice($imageList,$startimage,$instance['items']);
                                  foreach($DisplayArray as $image) {
    // Same code as the foreach (imagelist as image)
    echo $out . ''."\n";
                                // Code for pagination << and >>
                                  if ($pagenum==1) {
                                    echo "<a href='$pagenow?pagenum=$next'> >> </a>";
                                  elseif($pagenum==$totalpages) {
                                    echo "<a href='$pagenow?pagenum=$previous'> << </a>";
                                  else {
                                    echo "<a href='$pagenow?pagenum=$next'> >> </a>";
                                    echo "  " ;
                                    echo "<a href='$pagenow?pagenum=$previous'> << </a>";
                                 //Start of Original Code without Pagination
    			foreach($imageList as $image) {

    Thats it, I think I need to convert it to an independent function and call it from maybe page.php and update the page number as a parameter.

    I apologise if I haven’t explained it well there was a bit to get through. Any further details just ask and I’ll confirm or explain a little better.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: NextGEN Gallery] NextGen Widget Pagination’ is closed to new replies.