We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38142
    • 91 Posts
    I have set up getPage and it works nicely when friendly URLs are turned off. When they are turned on, the first page comes up fine, and the link to the next page of the paginated results looks like this:

    http://www.mysite.com/paginationtest.html?page=2
    


    But when you click the link the site flips back to the home page (although the browser address bar continues to show the URL with the query as indicated above).

    This is Revolution 2.1.5 on an admittedly questionable Windows server using an IIRF.ini file to get the friendly URLs working. I suspect this is a problem with the IIRF.ini file. I would be massively grateful if anyone can either confirm that and/or suggest a workaround to keep the getPage links working while FURLS are turned on.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      and the initial page is http://www.mysite.com/paginationtest.html?

      It's weird it would properly redirect without the url params, but fail with it. Definitely sounds like the FURL setup then. It probably gets "paginationtest.html?page=2" as the requested page, instead of "paginationtest.html" with "?page=2" as url properties.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 38142
        • 91 Posts
        Thanks for taking the trouble to reply, Mark. I have assumed that there is a clash between the URL rewriting script and the way getPage relies on inserting a query string into the URL, so I have set up a pagination system that doesn't rely on sending anything via the URL. It's not a system I would recommend to anyone else, but it works for this site.

        In case anyone else is in the same situation, I created a sufficiently large number of resources each with consecutive ID numbers and used those to display the paginated results. Each page calls a snippet to create the page links and passes to the snippet the number of the page so the snippet knows which page is the current one. That snippet also calculates how many links to display. Each page has a second snippet to display the set of results required for that particular page (calculated using the current page number).

        It is a bit of a dogs breakfast, but it works.

        For the record, the snippet calls (on the first resource) are:
        [[!pagination? &currentpage=`1`]]
        [[!arrangechildrenbytv? &currentpage=`1`]]
        [[!pagination? &currentpage=`1`]]


        The arrangechildrenbytv snippet collates a list of child resources ordered according to some TVs and then selects a group of them to be shown on the page:

        <?php
        $parentID = '22';
        $tvname1 = 'region';
        $tvname2 = 'sleeps';
        $tplname = 'villalist';
        $pagetitle = 'pagetitle';
        $introtext = 'introtext';
        $resultstodisplay = '12';
        
        $villaIDs = array();
          	
        $parentresource = $modx->getObject('modResource',array(
            'published' => 1,
            'id' => $parentID
        ));
        
          $children = $parentresource->getMany('Children');
            foreach ($children as $child) {
        	 	  $region = $child->getTVValue($tvname1);
        		  $sleeps  = $child->getTVValue($tvname2);
        		  if ( ($region == 'Minho') && ($sleeps == '14-plus') ) {    	$vid = $child->get('id');      $cat1 .=   $vid . '|'; }
        		    elseif ( ($region == 'Minho') && ($sleeps == '9-13') ) {    	$vid = $child->get('id');	$cat2 .=   $vid . '|'; }
        		      elseif ( ($region == 'Minho') && ($sleeps == '5-8') ) {    	$vid = $child->get('id');	$cat3 .=    $vid . '|'; }
        		      	 elseif ( ($region == 'Minho') && ($sleeps == '1-4') ) {   $vid = $child->get('id');	$cat4 .=    $vid . '|'; }
            } //end foreach
            
        $allvillas = $cat1 . $cat2. $cat3 . $cat4 ;
        
        $allvillas = trim($allvillas);
        
        //remove last | from string
        $allvillas = substr($allvillas, 0, -1);
        
        $villaarray = explode("|", $allvillas);
        
        $villacount = count($villaarray);
        
        $i = 1;
        $startpage = ( $currentpage * 12) - 11;
        $tobreak = ( $currentpage * 12 ) + 1;
        
            foreach ($villaarray as $key => $villa) {
        	     if(($i >= $startpage)  && ($i < $tobreak)) { 
        
        			$villaid = $villa;
        			$villa = $modx->getObject('modResource',$villaid);
        			$titletoprint = $villa->get('pagetitle');
        			$introtoprint = $villa->get('introtext');
        			$regiontoprint = $villa->getTVValue('region');
        			$maintoprint = $villa->getTVValue('mainsummarylist');
        			$secondtoprint = $villa->getTVValue('secondsummarylist');
        			$locationtoprint = $villa->getTVValue('location');
        			$gallerypathtoprint = $villa->getTVValue('gallerypath');
        			
        			$output .= $modx->getChunk($tplname, array(
        'pagetitle' => $titletoprint,
        'introtext' => $introtoprint,
        'region' => $regiontoprint,
        'location' => $locationtoprint,
        'mainsummarylist' => $maintoprint,
        'secondsummarylist' => $secondtoprint,
        'id' => $villaid,
        'gallerypath' => $gallerypathtoprint
        
        ));
        	     }		
         $i++;			
        			
         } //end foreach
                return $output;
        
        ?>
        	
        	


        The pagination snippet uses a tiny chunk to create the page numbers as list items with links:

        <?php
        
        $parentID = '22';
        $resultstodisplay = '12';
        $firstpageid = '254';
        $tpl = 'paginationlistitem';
        
        $children = $modx->getChildIds( $parentID );
        $sumofchildren = count($children);
        
        if($sumofchildren > $resultstodisplay) {
            $pagestotal = ceil($sumofchildren/$resultstodisplay);
        }
        
        if($pagestotal > 1) {
            $lastpageid = ($firstpageid + $pagestotal) - 1 ;
            
            $output = '<div class="pagenav"><ul>';}
        
        $i = 1; 
        
           while($i <= $pagestotal){
        $rid =  ($firstpageid + $i) - 1;
        
        	$pagenumbertoprint = $i ;
        	    if($pagenumbertoprint != $currentpage){
        	       $output .= $modx->getChunk($tpl, array(
                      'rid' => $rid,
                          'pagenumbertoprint' => $pagenumbertoprint
               	));
        	    } elseif($pagenumbertoprint == $currentpage) {
        	    $output .= '<li>'.$pagenumbertoprint.'</li>';
        	}
        $i++;
            }//end while
            $output .= '</ul></div>';
        }//end if pagestotal
        return $output; 


          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Looks like an awful lot of code there!

          Surely there has to be a better way, but if it works and you're happy with it I guess that's the desired end result. wink
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.