We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22797
    • 134 Posts
    I just spent asome time trying to figure out why the pagination links weren’t working. I was able to generate the links successfully, and they did indeed change the url appropriately when I clicked on them, but no matter which page link I clicked on, it always gave me the first page of results, no matter what the url said. I couldn’t get page 2 or 3 or anything else.

    I got into the code in ditto.class.inc.php and after some troubleshooting I realized that the variable was not being passed from the URL to the code. The value of $start was always 0.

    So I added these lines of code to the source, which made it work:


    if (ereg("start=", $_SERVER['REQUEST_URI']))
    {
    	$start1 = split("start=", $_SERVER['REQUEST_URI']);
    	$start = $start1[1];
    	
    }



    I have no idea why that was necessary. I had a similar problem with another snippet, and now I think I’ll be able to solve it the same way. I haven’t seen any other posts in the discussion forum about this, so there is likely something in the way that my MODx is configured or hacked, but the code that I used is simple, and I don’t think it would break it for anyone else. Is there a chance this (or something like it) can be included in future releases? (Please? ... so I don’t have to add it to every new release?)
      • 22797
      • 134 Posts
      I spoke a little too soon about the above code solving the problem. I had to make the page not cacheable to have that work, but now the list of pages in the previous/next group is not fully functional. It lists links only for the pages from the current point forward. I’m sure this is fixable, but I’ve already been up too late trying to work through it, so I’m going to leave it until later. Here’s the section of code in ditto.class.inc.php that is affected:

      		for ($x = 0; $x <= $totalpages -1; $x++) {
      			$inc = $x * $summarize;
      			$display = $x +1;
      			if ($inc != $start) {
      				$pages .= "<a class=\"ditto_page\" href=\"".$this->buildURL("start=$inc")."\">$display</a> ";
      			} else {
      				$modx->setPlaceholder($dittoID."currentPage", $display);
      				$pages .= "<span class=\"ditto_currentpage\">$display</span> ";
      			}
      		}
      
        • 18397
        • 3,250 Posts
        1. What is your Ditto call?
        2. What version of Ditto are you using? 2.0.2?
        3. The code you have changed uses ereg which is extremely slow. Also, without appending $dittoID it won’t work with Ditto ID’s. PHP provides access to all GET variables (querystring) via the superglobal $_GET array in all versions after 4.1.0. Are you using a version prior to this?
        4. Can you place the following in a new snippet then access it with &start=40 in the URL
        return $_GET['start'];
        

        If it does not return 40 there is a configuration problem on your server that is causing the issue. If it does, then something else is wrong and more troubleshooting will be needed.
          • 22797
          • 134 Posts
          Thanks for your responses.

          1. Here is the Ditto call:

          [[Ditto? &parents=`3026`  &depth=`1` &extenders=`summary` &tpl=`ditto.CoreValues` &trunc=`0` &paginate=`1` &summarize=`5` &tagDelimiter=`,` &tagData=`CoreValues` &tags=`Collaboration` &paginateAlwaysShowLinks=`1` &paginateSplitterCharacter=` | ` ]]
          
          <p>Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles | Page <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong></p> 
          
          <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div>
          


          2. I’m using Ditto 2.0.2

          3. I’m using PHP 5.2.1

          4. The $_GET[’start’] code works on stand-alone PHP files, but not within a snippet.
            • 10487 MODX Staff
            • 1,535 Posts
            4. The $_GET[’start’] code works on stand-alone PHP files, but not within a snippet.
            Have you tried calling the snippet uncached (like [!....!])? That is most probably what is causing this behaviour.
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 22797
              • 134 Posts
              When I put in the uncached snippet call ( [! !] ), it sends me to the 404 error page. I have PHx installed, which I read elsewhere could be a problem, so I disabled it, but the result is the same: 404 error. The page itself is not set to be cached.
                • 22797
                • 134 Posts
                Clarification: The 404 error is when I call the Ditto snippet using [! !]

                When I call my simple snippet with only the GET function, it does not give me the 404 error, but it also does not return the value from the url. Here’s the full source code for my test snippet:

                <?php
                $start=$_GET['start'];
                echo "<h1>".$start."</h1>";
                ?>
                
                  • 22797
                  • 134 Posts
                  UPDATE: I’ve found the root of the problem. As I suspected, it didn’t have anything to do with Ditto, really. It has to do with a plugin that one of our programmers developed that manipulates the URL. I had tried diabling the plugin before, in an effort to pinpoint the problem, with no luck. But then I went into the the MODx source code where he had done a minor edit... which in this case turns out to make a big difference.

                  I haven’t yet fixed the problem, but I now know where to fix it. Sorry to have taken up your time with something that turns out to be unrelated. But I do appreciate the quick responses.

                  (I tried to eliminate the possibly unrelated causes, but apparently overlooked this one thing.)