We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24922
    • 1 Posts
    The SplitPagination download seems to be broken:
    http://modxcms.com/extras.html?view=download&version=138&file=138

    I really need to use this snippet. Could someone post the latest source for it, please?

    Thank you!
      • 32163
      • 33 Posts
      Some hours ago I met the same problem as you. So I have surfed all around the forum accurately and finally found an improved code of splitPagination snippet in its own help topic. Look here - http://modxcms.com/forums/index.php/topic,14590.msg94973.html#msg94973
      And here is the code:

      <?php
      // Snippet: splitPagination
      // Must be placed immediately following a Ditto call
      // Based on the function written by Aaron Hall, evilwalrus.org
      if (!function_exists("generatePagination")) {
      function generatePagination($curPage, $totResults, $resultsPerPage)
      {
      	$totPages = ceil($totResults / $resultsPerPage);
      	
      	$pagesBefore = $curPage - 1;
      	$pagesAfter = $totPages - $curPage;
      	
      	$tabArr = array();
      	
      	if($totPages > 15) {
      		
      		if($pagesBefore > 7) {
      			$tabArr = array(1,2,0);
      			
      			if($pagesAfter > 7)
      			{
      				for($i=($curPage-(4)); $i<$curPage; $i++) { $tabArr[] = $i; }
      			} else {
      				for($i=($totPages-11); $i<$curPage; $i++) { $tabArr[] = $i; }
      			}
      		} else {
      			for($i=1; $i<$curPage; $i++) { $tabArr[] = $i; }
      		}
      		
      		$tabArr[] = $curPage;
      		
      		if($pagesAfter > 7) {
      			if($pagesBefore > 7) {				
      				for($i=($curPage+1); $i<=$curPage+4; $i++) { $tabArr[] = $i; }
      			} else {
      				for($i=($curPage+1); $i<13; $i++) { $tabArr[] = $i; }
      			}
      			$tabArr[] = 0;
      			$tabArr[] = $totPages-1;
      			$tabArr[] = $totPages;
      		} else {
      			for($i=($curPage+1); $i<=$totPages; $i++) { $tabArr[] = $i; }
      		}
      		
      	} else {
      		for($i=1;$i<=$totPages;$i++) { $tabArr[] = $i; }
      	}
      			
      	return $tabArr;
      	
      }
      }
      $id = isset($id) ? $id.'_' : '';
      $total = isset($total) ? $total : $modx->getPlaceholder($id."total");
      $start = isset($start) ? $start : $modx->getPlaceholder($id."start");
      $display = isset($display) ? $display : $modx->getPlaceholder($id."perPage");
      $currentPage = isset($currentPage) ? $currentPage : $modx->getPlaceholder($id."current");
      $landing = isset($tagDocumentID) ? $tagDocumentID : $modx->documentObject['id'];
      if ($total == 0 || $display==0) {
      	return false;
      }
      $page = ceil($start/$display);
      $return = isset($return) ? $return : 0;
      $paginationArray = generatePagination($page, $total, $display);
      $ph = "";
      $cInc = $_GET[$id.'start'];
      foreach($paginationArray as $page) {
      	$inc = ($page-1)*$display;
      	if($page == 0) {
      		$ph .= "..."; // print an elipse, representing pages that aren't displayed
      	} else if ($inc==$cInc) {
      		$ph .= "<span class=\"ditto_currentpage\">$page</span>";		
      	} else {
      		$ph .= "<a class=\"ditto_page\" href='".ditto::buildURL("start=".$inc,$landing,$id)."'>$page</a>";
      	}
      	
      
      }
      $modx->setPlaceholder($id."splitPages",$ph);
      if ($return) return $ph;
      ?>