We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27022
    • 47 Posts
    I'm having an issue getting pagination to work with the Cliche extra. I used this http://forums.modx.com/thread/86214/use-cliche-gallery-and-getpage-for-pagination-to-display-x-number-of-images as my guide to adding pagination, as Adrian Cherry found that pagination was included, but maybe the issue is that it's not ready for primetime yet. My issue is that the links that the pagination create do not actually load the next page, as the url it generates is missing the id of the gallery page.

    Here is the sample link it creates: Website/gallery.html?page=2
    However, the link should be: Website/gallery.html?view=album&cid=12&page=2 with the italics showing the portion that needs changed.

    Here is my albumwrapper chunk:
    <div class="cliche galleryid-[[+id]]" id="album-[[+id]]">
        <h2>[[+name]]</h2>
        <p>Page:[[+cliche.current_page]] of [[+cliche.last_page]] 
        [[+cliche.current_page:gt=`1`:then=`<a href=[[~[[*id]]]]&page=1> :First: </a>`]]
        [[+cliche.page_link_prev]] 
        [[+cliche.page_link_next]] 
        [[+cliche.current_page:notequalto=`[[+cliche.last_page]]`:then=`<a href="[[~[[*id]]]]&page=[[+cliche.last_page]]"> :Last: </a>`]]</p>
        [[+items]]
    </div>
    <!-- End #album-[[+id]] -->



    Here is what I'm assuming is the problematic portion of the Cliche default.class.php

            $paginate = $this->getProperty('paginate', false);
            if( $paginate ){
                $pageVar = $this->getProperty('pageVar', 'page');
                $request = $this->modx->request->getParameters();
                $page = isset($request[$pageVar]) ? $request[$pageVar] : 1;
                $start = ceil($paginate * $page  + 1) - $paginate;
                $query->limit($paginate, $start);
                
                /* Prepare pagiantion */
                $lastPage = ceil($total / $paginate);
                $prevLink = $this->getPaginationLink($pageVar, $page, $this->getProperty('prevLinkText', '<< prev'));
                $nextLink = $this->getPaginationLink($pageVar, $page, $this->getProperty('nextLinkText', 'next >>'), 'next', $lastPage);
                
                /* Simple pagination */
                $phs = array(
                    $this->getProperty('totalPagePlaceholder', 'cliche.current_page') => $page,
                    $this->getProperty('nextLinkPlaceholder', 'cliche.page_link_next') => $nextLink,
                    $this->getProperty('prevLinkPlaceholder', 'cliche.page_link_prev') => $prevLink,
                    $this->getProperty('lastPagePlaceholder', 'cliche.last_page') => $lastPage,
                );            
                $this->controller->setPlaceholders($phs);
            }
            
            return $query;
        }
        
        
        /**
         * Get a simple link for pagination
         * 
         * @param string $pageVar The query string variable to use for the link
         * @param integer $page The current page number
         * @param string $text The text of the link
         * @param string $action The action to link to (prev or next page)
         * @param integer $lastPage The last page number
         * @return string $link The page link or an empty string
         */
        public function getPaginationLink($pageVar, $page, $text, $action = 'prev', $lastPage){        
            $showParams = true;
            if($action == 'next'){   
                $page = $page + 1;
                if($page > $lastPage) return ''; 
            } else {   
                if($page == 1) return '';
                $page = $page - 1;
                if($page == 1) $showParams = false;            
            }
            $params = $showParams ? array( $pageVar => $page ) : array();
            
            $url = $this->modx->makeUrl( $this->modx->resource->get('id'),'',$params); 
            $link = "<a href=\"{$url}\">{$text}</a>";
            return $link;
        }
    



    Am I overlooking something, or is there an issue with the PHP? Any help is greatly appreciated. Thanks!