We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28120
    • 380 Posts
    Anyone got a snippet or package that will allow me to display the last n viewed pages - probably have to specify viewed below a specific parent(s)

    Thanks

    Mark
      • 31654
      • 238 Posts
      I'm also looking for a "recently viewed resources" which can be templates via chunks to use TVs from viewed resources. Also params to customise the amount of history output (default would be 5 or 10 resources).
        Web Development, Web Hosting & Search Engine Marketing by:

        Vitalized | UK
        w. www.vitalized.co.uk

        Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

        Vitalized | Australia
        w. www.vitalized-australia.com.au

        Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
        • 4172
        • 5,888 Posts
        Is this for logged in users? Than its easy to log the history in a custom-table.
        Otherwise you will need to work with sessions and cookies, perhaps also in addition with a custom-table.
        What to choose depends on your requirements.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 31654
          • 238 Posts
          That's a good question. For the site I'm currently creating it would be good or both situations. It's a property rental website so it would be great if it remembers what the user has viewed before & after login.
            Web Development, Web Hosting & Search Engine Marketing by:

            Vitalized | UK
            w. www.vitalized.co.uk

            Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

            Vitalized | Australia
            w. www.vitalized-australia.com.au

            Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            When I see stuff like that on sites I always wonder if that's really true or if they're just grabbing random items...

            Wouldn't it make more sense (and get more people to click through) if you'd include a listing of related items to the one currently on screen instead? There's getRelated for that which you can integrate, I don't think there's any Extra currently available that'll get the latest viewed for you and list those. Like Bruno says it wouldn't be too shocking to develop, but my gut says you're not a PHP dev tongue
              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.
              • 31654
              • 238 Posts
              You're right I'm not a PHP dev at all!
                Web Development, Web Hosting & Search Engine Marketing by:

                Vitalized | UK
                w. www.vitalized.co.uk

                Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

                Vitalized | Australia
                w. www.vitalized-australia.com.au

                Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
                • 30176
                • 99 Posts
                Actually, I think that there is a good usage of this. If you filter articles from a number of containers, the breadcrumb does not show you how to get back. Secondly, if you are looking at items for purchase, it will show the ones that you have just looked at for reference.
                  "Remember what Bilbo used to say: It's a dangerous business, Frodo, going out your door. You step onto the road, and if you don't keep your feet, there's no knowing where you might be swept off to."
                  -J.R.R. Tolkien from The Lord of the Rings
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Hmm I think I read the request differently (reading back now, probably not the way it was intended) when I made my post...

                  The use case you describe makes sense wink

                  Here's a quick thing to help you get started:

                  Plugin to trigger on OnWebPageComplete (though could also try OnWebPageLoad, haven't tested what event is best in this case):
                  <?php
                  if (!isset($_SESSION['recent.' . $modx->context->get('key') ])) {
                    $s = $_SESSION['recent.' . $modx->context->get('key') ] = array();
                  } else {
                    $s = $_SESSION['recent.' . $modx->context->get('key') ];
                  }
                  $id = $modx->resource->get('id');
                  // Prevent getting the same page in the list. Unsetting it here & re-adding it later makes it top of the list again.
                  if (in_array($id, $s)) {
                    unset ($s[array_search($id, $s)]);
                  }
                  
                  array_unshift($s, $id);
                  
                  $_SESSION['recent.' . $modx->context->get('key') ] = $s;


                  Snippet to get the list of IDs as comma separated list (name it getRecentViewed):
                  if (!isset($_SESSION['recent.' . $modx->context->get('key') ])) {
                    $s = $_SESSION['recent.' . $modx->context->get('key') ] = array();
                  } else {
                    $s = $_SESSION['recent.' . $modx->context->get('key') ];
                  }
                  return implode(',',$s);


                  Example usage:
                  [[!getResources? &resources=`[[!getRecentViewed]]` &parents=`1,2,3` &tpl=`customChunkToDisplayWith`]]


                  Untested
                    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.