We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32645
    • 377 Posts
    We are using Ditto on articles and paginating the content.

    We have a back to top link which is designed to go back to the top of the page, however if we go to the next page the back to top link returns to the start page.

    How do we make it so that the back to top only returns to the top of the page you are on.
      • 1122
      • 209 Posts
      I have special fondness to this issue -- it looks very simple and funny, but, unfortunately, it has no funny solution. You need to build your "topofpage" link manually and take care of preserving all query vars used by Ditto to navigate through its pages:
      1) the simplier part:
      <a href="[(site_url)][!self_reference!]#topofpage">topofpage</a>
      (of course, do not forget to create topofpage anchor ;)
      ------
      2) the gory rest -- "self_reference" snippet
      <?php
      /*
       Self Reference - returns current url preserving all query variables
       Copyright (c) 2009 Aleksander Maksymiuk, http://setpro.net.pl/
       You can check latest release at
          http://setpro.net.pl/software/self-reference#attachments
      */
      parse_str(htmlspecialchars_decode($_SERVER['QUERY_STRING']), $query_vars);
      if (isset($query_vars['q'])) {
        # we are within MODx
        $retscript = $query_vars['q'];
        unset($query_vars['q']);
      } else {
        # not a MODx (or we are on / page), but it has to work anyway
        $retscript = $_SERVER['PHP_SELF']; /* 1 */
      }
      if (count($query_vars)) {
        $retqstr = '';
        foreach ($query_vars as $var => $value) {
          $retqstr .= '&' . $var . '=' . htmlspecialchars($value);
        }
        $retqstr = preg_replace('/^&/i', '', $retqstr);
        return $retscript . '?' . $retqstr;
      } else {
        return $retscript;
      }
      ?>
      

      The snippet works with either MODx or any other PHP-driven site. If it runs within MODx it takes into account that url may be rewritten with mod_rewrite and behaves properly. If you find it useful, you can use it (please preserve author’s info -- creating the snippet took me a while).
        • 12630
        • 22 Posts
        Hi,

        This looks like the exact fix I need.

        However, I am getting the following error:-

        Fatal error: Call to undefined function: htmlspecialchars_decode() in ../manager/includes/document.parser.class.inc.php(770) : eval()’d code on line 7

        I am running Evolution 1.0.2

        Any ideas?


          • 1122
          • 209 Posts
          This error is related to your PHP version. Function htmlspecialchars_decode() is implemented in PHP 5.1.0 (and newer).
            • 12630
            • 22 Posts
            Hi alik,

            Thanks for that. I have sorted the php version issue but the snippet still does not seem to work. There is no error now.

            I have created the snippet with your latest version:-

            <?php
            /*
            SelfReference - returns current url preserving all query variables
            Copyright (c) 2009-2010 Aleksander Maksymiuk, http://setpro.net.pl/
            You can check latest release at
            http://setpro.net.pl/software/self-reference#attachments
            Revision: January 9, 2009
            */

            define(’SITE_START’, ’’);

            parse_str(htmlspecialchars_decode($_SERVER[’QUERY_STRING’]), $query_vars);
            if (isset($query_vars[’q’])) {
            # we are within MODx
            $retscript = $query_vars[’q’];
            unset($query_vars[’q’]);
            } else {
            # not MODx (or we are on site’s start), but it has to work anyway
            $retscript = $_SERVER[’PHP_SELF’]; /* 1 - it can be resolved in this way or... */
            ####$retscript = SITE_START; /* 2 - ... in this */
            }
            if (count($query_vars)) {
            $retqstr = ’’;
            foreach ($query_vars as $var => $value) {
            $retqstr .= ’&amp;’ . $var . ’=’ . htmlspecialchars($value);
            }
            $retqstr = preg_replace(’/^&amp;/i’, ’’, $retqstr);
            return $retscript . ’?’ . $retqstr;
            } else {
            return $retscript;
            }
            ?>

            The page code is as follows:-

            <strong>Local Issues</strong>

            [[Ditto? &startID=`8` &summarize=`4`&tpl=`news_format` &paginate=`1` &paginateAlwaysShowLinks=`1` SelfReference? &redir=`[+alias+]`]]



            Showing <strong>[+start+]</strong> -
            <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles | Page
            <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong>



            <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div>

            As you can probably tell I have very limited knowledge on modx and php etc. I still have the same problem in that when I click on a link in the second page it returns the correct page content but with the first page links.

            You can see the issue at http://icomlocal.com/index.php?id=8

            I am using friendly urls.

            I am sure I have not implemented your solution incorrectly but I do not have the knowledge to figure out what I have done wrong.

            Cheers

            iCOM


              • 878
              • 4 Posts
              Hey all, this is so great. I am so happy that I stumbled upon this thread. I have been searching for a solution for this exact problem but never got it done any where. But now I got it over here. Thanks a lot for the help. I will try it soon.
                Life