We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38865
    • 10 Posts
    Hi there,

    I have an unordered list of items that are rendered to the page using getPage. The items are displayed in a number of pages with pagination and that all works great. Now what I'd like to be able to do is link to the page that this list is on, passing a param like ?itemid=12 and then when the paged content loads, go to the pagination page that the item is on and select it.

    I'm relatively new with Modx so my apologies if a solution to this issue exists already. The forums are great but I find searching them diffucult as there's no easy way to return results just for a certain topic or more importantly just for Revolution (or is there and I just don't know how).

    Any help would be greatly appreciated. I'm running latest ver of Revolution and latest version of getPage.

    Thanks in advance!
    Phill
      • 4172
      • 5,888 Posts
      something like that should work:

      create a snippet 'getpaginationmap'

      <?php
      
      $limit=$scriptProperties['limit'];
      $scriptProperties['limit'] = '0';
      $scriptProperties['tpl'] = '@INLINE [[+id]]';
      $scriptProperties['outputSeparator'] = ',';
      
      $result = $modx->runSnippet('getResources',$scriptProperties);
      
      $resids = explode(',',$result);
      
      $page = 1;
      $counter = 1;
      foreach ($resids as $resid){
          $paginationmap[$resid]=$page;
      
          if ($counter == $limit){
              $counter = 1;
              $page ++;
          }    
          $counter ++;
      }
      return $modx->toJson($paginationmap);
      


      and another snippet which redirects to the paginated page 'redirectToPage':

      <?php
      
      $paginationmap = $modx->fromJson($paginationmap);
      
      if (isset($_REQUEST['itemid'])){
          $page = $paginationmap[$_REQUEST['itemid']];
          $modx->sendRedirect($modx->makeUrl($redirectTo,'','&page='.$page.'&item='.$_REQUEST['itemid']));
      }
      


      call it the same way as you call your getPage-snippet.

      [[!redirectToPage? 
      &redirectTo=`2` 
      &paginationmap=`[[getpaginationmap? &limit=`2` &parents=`11,10`]]`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!