We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46309
    • 79 Posts
    Hi everybody,
    I have the folowing problem:
    I'm using Gallery 1.5.2 in MODx Cloud and I'm trying to make a pagination with getPage, but when i come to the area with the images inside the albums, only the thumbs are showing and there is no pagination.
    Does anyone have an idea how to solve the problem? I need the pagination only for the section with the images: Gallery Albums -> list of images(Gallery).
    Here are my chunk codes:
    <div class="pagenav"> 
    <ul> 
       [[!+page.nav]] 
    </ul>
    </div>
    
    [[!GalleryAlbums? 
    &toPlaceholder=`GalleryAlbums` 
    &limit=`0` 
    &dir=`asc` 
    &albumCoverSort=`rank` 
    &prominentOnly=`1` 
    &rowTpl=`tonitaAlbumRowTpl`
    &thumbWidth=`150` 
    &thumbHeight=`150`]]
     
    [[!getPage?  
        &elementClass=`modSnippet`
        &offest=`0`
        &totalVar=`total`
    
    
    &element=`Gallery`
    &limit=`8`
    &checkForRequestTagVar=`1` 
    &toPlaceholder=`Gallery` 
    &useCss=`0` 
    &containerTpl=`tonitaAlbumContainer` 
    &thumbWidth=`150` 
    &thumbHeight=`150` 
    &thumbTpl=`tonitaItemThumb` 
    &imageHeight=`1000` 
    &imageWidth=`1000`
    &pageLimit=`5`
    ]]
     
    [[!If? 
    &subject=`[[+Gallery]]` 
    &operator=`isempty` 
    &then=`[[+GalleryAlbums]]` 
    &else=`[[+Gallery]]`]]
    


    tonitaAlbumRowTpl:
    <div class="gallery-section">
        <div class="gallery-title">[[+name]]</div>
        <div class="thumb-album shadow">
    		<div class="thumb-wrapper">
            <a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]">
            <img src="[[+image]]" alt="[[+name]]" width="150" height="150" />
            </a>
            </div>
        </div>
    </div>


    tonitaAlbumContainer:

    <!-- Album title -->
    <div class="titlebar">
        <div class="album-title">
            <span class="title">[[+album_name]]</span> 
        </div>
    </div>
    
    <!-- Album description
    <p>[[+album_description]]</p>-->
    [[+thumbnails]]
    
    <!-- DIV clear -->
    <div class="clear"></div>


    tonitaItemThumb:
    <div class="album-section">
    <div class="thumb shadow">
    	                <div class="thumb-wrapper">
        <a href="[[+image]]" class="albumpix" rel="lightbox" data-lightbox="[[+album_name]]" title="[[+description]]">
            <img src="[[+image]]" alt="[[+name]]" width="150" height="150"/>
        </a>
    </div>
    </div>
    </div>


    and my getPage snippet (edited on line 41 with $properties['start'] = $properties['offset'];):
    <?php
    /**
     * @package getpage
     */
    $output = '';
    
    $properties =& $scriptProperties;
    $properties['page'] = (isset($_GET[$properties['pageVarKey']]) && ($page = intval($_GET[$properties['pageVarKey']]))) ? $page : null;
    if ($properties['page'] === null) {
        $properties['page'] = (isset($_REQUEST[$properties['pageVarKey']]) && ($page = intval($_REQUEST[$properties['pageVarKey']]))) ? $page : 1;
    }
    $properties['limit'] = (isset($_GET['limit'])) ? intval($_GET['limit']) : null;
    if ($properties['limit'] === null) {
        $properties['limit'] = (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : intval($limit);
    }
    $properties['offset'] = (!empty($properties['limit']) && !empty($properties['page'])) ? ($properties['limit'] * ($properties['page'] - 1)) : 0;
    $properties['totalVar'] = empty($totalVar) ? "total" : $totalVar;
    $properties['total'] = !empty($properties['total']) && $total = intval($properties['total']) ? $total : 0;
    $properties['pageOneLimit'] = (!empty($pageOneLimit) && $pageOneLimit = intval($pageOneLimit)) ? $pageOneLimit : $properties['limit'];
    $properties['actualLimit'] = $properties['limit'];
    $properties['pageLimit'] = isset($pageLimit) && is_numeric($pageLimit) ? intval($pageLimit) : 5;
    $properties['element'] = empty($element) ? '' : $element;
    $properties['elementClass'] = empty($elementClass) ? 'modChunk' : $elementClass;
    $properties['pageNavVar'] = empty($pageNavVar) ? 'page.nav' : $pageNavVar;
    $properties['pageNavTpl'] = !isset($pageNavTpl) ? "<li[[+classes]]><a[[+classes]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageNavTpl;
    $properties['pageNavOuterTpl'] = !isset($pageNavOuterTpl) ? "[[+first]][[+prev]][[+pages]][[+next]][[+last]]" : $pageNavOuterTpl;
    $properties['pageActiveTpl'] = !isset($pageActiveTpl) ? "<li[[+activeClasses:default=` class=\"active\"`]]><a[[+activeClasses:default=` class=\"active\"`]][[+title]] href=\"[[+href]]\">[[+pageNo]]</a></li>" : $pageActiveTpl;
    $properties['pageFirstTpl'] = !isset($pageFirstTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">First</a></li>" : $pageFirstTpl;
    $properties['pageLastTpl'] = !isset($pageLastTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">Last</a></li>" : $pageLastTpl;
    $properties['pagePrevTpl'] = !isset($pagePrevTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\"><<</a></li>" : $pagePrevTpl;
    $properties['pageNextTpl'] = !isset($pageNextTpl) ? "<li class=\"control\"><a[[+title]] href=\"[[+href]]\">>></a></li>" : $pageNextTpl;
    $properties['toPlaceholder'] = !empty($toPlaceholder) ? $toPlaceholder : '';
    $properties['cache'] = isset($cache) ? (boolean) $cache : (boolean) $modx->getOption('cache_resource', null, false);
    if (empty($cache_key)) $properties[xPDO::OPT_CACHE_KEY] = $modx->getOption('cache_resource_key', null, 'resource');
    if (empty($cache_handler)) $properties[xPDO::OPT_CACHE_HANDLER] = $modx->getOption('cache_resource_handler', null, 'xPDOFileCache');
    if (empty($cache_expires)) $properties[xPDO::OPT_CACHE_EXPIRES] = (integer) $modx->getOption('cache_resource_expires', null, 0);
    
    if ($properties['page'] == 1 && $properties['pageOneLimit'] !== $properties['actualLimit']) {
        $properties['limit'] = $properties['pageOneLimit'];
    }
    $properties['start'] = $properties['offset'];
    if ($properties['cache']) {
        $properties['cachePageKey'] = $modx->resource->getCacheKey() . '/' . $properties['page'] . '/' . md5(http_build_query($modx->request->getParameters()));
        $properties['cacheOptions'] = array(
            xPDO::OPT_CACHE_KEY => $properties[xPDO::OPT_CACHE_KEY],
            xPDO::OPT_CACHE_HANDLER => $properties[xPDO::OPT_CACHE_HANDLER],
            xPDO::OPT_CACHE_EXPIRES => $properties[xPDO::OPT_CACHE_EXPIRES],
        );
    }
    $cached = false;
    if ($properties['cache']) {
        if ($modx->getCacheManager()) {
            $cached = $modx->cacheManager->get($properties['cachePageKey'], $properties['cacheOptions']);
        }
    }
    if (empty($cached) || !isset($cached['properties']) || !isset($cached['output'])) {
        $elementObj = $modx->getObject($properties['elementClass'], array('name' => $properties['element']));
        if ($elementObj) {
            $elementObj->setCacheable(false);
            if (!empty($properties['toPlaceholder'])) {
                $elementObj->process($properties);
                $output = $modx->getPlaceholder($properties['toPlaceholder']);
            } else {
                $output = $elementObj->process($properties);
            }
        }
    
        include_once $modx->getOption('getpage.core_path',$properties,$modx->getOption('core_path', $properties, MODX_CORE_PATH) . 'components/getpage/').'include.getpage.php';
    
        $qs = $modx->request->getParameters();
        $properties['qs'] =& $qs;
    
        $totalSet = $modx->getPlaceholder($properties['totalVar']);
        $properties['total'] = (($totalSet = intval($totalSet)) ? $totalSet : $properties['total']);
        if (!empty($properties['total']) && !empty($properties['actualLimit'])) {
            if ($properties['pageOneLimit'] !== $properties['actualLimit']) {
                $adjustedTotal = $properties['total'] - $properties['pageOneLimit'];
                $properties['pageCount'] = $adjustedTotal > 0 ? ceil($adjustedTotal / $properties['actualLimit']) + 1 : 1;
            } else {
                $properties['pageCount'] = ceil($properties['total'] / $properties['actualLimit']);
            }
        } else {
            $properties['pageCount'] = 1;
        }
        if (empty($properties['total']) || empty($properties['actualLimit']) || $properties['total'] <= $properties['actualLimit'] || ($properties['page'] == 1 && $properties['total'] <= $properties['pageOneLimit'])) {
            $properties['page'] = 1;
        } else {
            $pageNav = getpage_buildControls($modx, $properties);
            $properties[$properties['pageNavVar']] = $modx->newObject('modChunk')->process(array_merge($properties, $pageNav), $properties['pageNavOuterTpl']);
            if ($properties['page'] > 1) {
                $qs[$properties['pageVarKey']] = $properties['page'];
            }
        }
        
        $properties['firstItem'] = $properties['offset'] + 1;
        $properties['lastItem'] = ($properties['offset'] + $properties['limit']) < $totalSet ? ($properties['offset'] + $properties['limit']) : $totalSet;
    
        $properties['pageUrl'] = $modx->makeUrl($modx->resource->get('id'), '', $qs);
        if ($properties['cache'] && $modx->getCacheManager()) {
            $cached = array('properties' => $properties, 'output' => $output);
            $modx->cacheManager->set($properties['cachePageKey'], $cached, $properties[xPDO::OPT_CACHE_EXPIRES], $properties['cacheOptions']);
        }
    } else {
        $properties = $cached['properties'];
        $output = $cached['output'];
    }
    $modx->setPlaceholders($properties, $properties['namespace']);
    if (!empty($properties['toPlaceholder'])) {
        $modx->setPlaceholder($properties['toPlaceholder'], $output);
        $output = '';
    }
    
    return $output;


    Thank you in advance for your help!

    Deyan




    [ed. note: deyand last edited this post 10 years, 2 months ago.]
      peace&love / bike&ride
      • 46309
      • 79 Posts
      I tried something different - the eugen.t's solution and almost did it http://forums.modx.com/thread/37769/revolution-gallery---how-to-add-pagination?page=2#dis-post-439685
      There is already a pagination, but the problem is, that when I come to the page with images it shows also the albums list below and I want to show only the images from the corresponding album.
      I think it's something with the If snippet, but i'm not so familiar with it and also a newbie, so I will be glad if anybody can help me.
      Here are the codes:
      <div class="pagenav"> 
      <ul> 
         [[!+page.nav]] 
      </ul>
      </div> 
      
      [[!GalleryAlbums? 
      &toPlaceholder=`GalleryAlbums` 
      &limit=`0` 
      &dir=`asc` 
      &albumCoverSort=`rank` 
      &prominentOnly=`1` 
      &rowTpl=`tonitaAlbumRowTpl`
      &thumbWidth=`150` 
      &thumbHeight=`150`]]
       
      [[!getPage?
      &elementClass=`modChunk`
      &element=`gallery_wrapper`
      &limit=`5`
      &totalVar=`gallery.total`
      ]]
       
      [[!If? 
      &subject=`[[+Gallery]]` 
      &operator=`isempty` 
      &then=`[[+GalleryAlbums]]` 
      &else=`[[+Gallery]]`]]
      


      gallery_wrapper:
      [[!Gallery? 
      &limit=`[[+limit]]`
      &start=`[[+offset]]`
      &album=`[[*alias]]`
      &limit=`8`
      &useCss=`0` 
      &containerTpl=`tonitaAlbumContainer` 
      &thumbWidth=`150` 
      &thumbHeight=`150` 
      &thumbTpl=`tonitaItemThumb` 
      &imageHeight=`1300` 
      &imageWidth=`1300`
      &pageLimit=`5`
      &pageNavVar=`page.nav`
      ]]
      
      


      tonitaAlbumRowTpl, tonitaAlbumContainer and tonitaItemThumb - same as above.

      [ed. note: deyand last edited this post 10 years, 2 months ago.]
        peace&love / bike&ride
        • 41633
        • 13 Posts
        I think you should add
        &toPlaceholder=`Gallery`
        to your getPage snippet call, like this:
        [[!getPage?
        &elementClass=`modChunk`
        &element=`gallery_wrapper`
        &limit=`5`
        &totalVar=`gallery.total`
        &toPlaceholder=`Gallery`
        ]]
        


        Because you did not set [[+Gallery]] anywhere the condition in IF snippet is always TRUE, so you always get the content of [[+GalleryAlbums]].

        P.S. By the way Gallery is not good name for placeholder, because you can confuse it with Gallery snippet.
          • 46309
          • 79 Posts
          Thank you for the quick response eugen.t!
          I've tried your insructions, but unfortunatelly nothings happend - it's the same situation, or it's not working.
          The [[+Gallery]] settings are placed in my gallery_wrapper chunk.
          Maybe I'm doing something wrong.


          Here is the solution after the help from eugen.t:

          So, I've made some new corrections using eugen.t's method with gallery_wrapper snippet for Gallery and made it working smiley
          I'm posting it here in case anybody have the same situation or just for information.
          Here are the details:
          Make new chunk for the template used for my main Gallery Album page - Resource document. Let's call it Gallery.
          [[!GalleryAlbums? &limit=`6` &prominentOnly=`1` &rowTpl=`myRowTpl`]]

          myRowTpl chunk:
          <div class="gallery-section">
          <!-- Description of the Gallery name thumbs-->
            <div class="gallery-title">[[+name]]</div>
            <div class="gallery-thumbs">
            <a href="/gallery/[[+description]].html" class="gallery_[[+id]]">
            <img src="[[+image]]" alt="[[+name]]" /></a>
            </div>
          </div>

          Made subdocuments in my Gallery document/Resource and gave them the name of the Albums which I'm going to show in my Gallery. They are linked to different template and I'm using getPage with eugen.t's gallery_wrapper chunk for it and some modifications for showing the pagination:
          [[!getPage? &elementClass=`modChunk` &element=`gallery_wrapper` &limit=`8`
          &totalVar=`gallery.total`]]

          gallery_wrapper chunk:
          [[!Gallery? 
          &limit=`[[+limit]]`
          &start=`[[+offset]]`
          &album=`[[*showAlbum]]`
          &limit=`8`
          &useCss=`0` 
          &containerTpl=`myAlbumContainer` 
          &thumbWidth=`150` 
          &thumbHeight=`150` 
          &thumbTpl=`myThumbTpl` 
          &imageHeight=`1000` 
          &imageWidth=`1000`
          &pageLimit=`5`
          &pageNavVar=`page.nav`
          ]]

          I've created [[*showAlbum]] TV with Input Type galleryalbumlist in the gallery_wrapper to show the albums, because the names are in Cyrilic (Bulgarian language) and [[+description]].html (English) in GalAlbumRowTpl to call each album.
          myAlbumContainer chunk:
          [[+thumbnails]]
          <!-- DIV clear -->
          <div class="clear"></div>

          myThumbTpl chunk:
          <a href="[[+image]]" class="albumpix" rel="lightbox" data-lightbox="[[+album_name]]" alt="[[+name]]">
                  <img src="[[+thumbnail]]" alt="[[+name]]" width="150" height="150"/>
              </a>


          That's it! smiley
          Thank you one more time for all your help eugen.t!



          [ed. note: deyand last edited this post 10 years, 2 months ago.]
            peace&love / bike&ride
            • 41633
            • 13 Posts
            I've used [[*longtitle]] (Cyrilic) in the gallery_wrapper to show the albums and [[+description]].html (English) in GalAlbumRowTpl to call each album, because their names are in cyrilic - Bulgarian language and the links are in English.
            Maybe you should use TV for album name instead using longtitle of resource?
              • 46309
              • 79 Posts
              Yeah,

              I should give it a try. Any advice?

              Edit: I've made new TV [[*showAlbum]] with Text Input and Output and then placed the value for every Album Resource.
              The gallery_wrapper chunk in my previous post is updated. [ed. note: deyand last edited this post 10 years, 2 months ago.]
                peace&love / bike&ride
                • 41633
                • 13 Posts
                That's exactly what i mean, but instead of using Input type Text use galleryalbumlist. This Input type appears when you install Gallery package, and generates dropdown list with all your albums, so you don't need to remember names of all galleries.
                  • 46309
                  • 79 Posts
                  Got it smiley
                  I didn't know about it, but it's really usefull smiley
                  Cheers!
                    peace&love / bike&ride
                    • 41633
                    • 13 Posts
                    You are welcome!
                      • 46309
                      • 79 Posts
                      One more thing to go:
                      Because the site is in two languages, how can I show the name/title of the gallery albums in each language?
                      I'm using [[+name]] in myRowTpl from the in [[!GalleryAlbums?]] snippet to show the name of the Album in the Gallery section, based on the name of each Album in my Gallery Components. It shows the Title, but in this situation if the names are in Bulgarian language by default, in the English section they are showing also in Bulgarian.
                      For the Albums inside the Gallery pages I have no problem with showing the names in different languages, based on [[*longtitle]].
                      How can i make this working?
                      I'm using Babel 2.2.5 for multilanguage if it matters.
                      Any ideas? [ed. note: deyand last edited this post 10 years, 2 months ago.]
                        peace&love / bike&ride