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

    I’d like to add a "new" icon beside each documents that are published before x days. I don’t know how to do, maybe with PHx, but I’m not enough experimented with it.
    Any idea anyone?

    Thanks!
      • 10226
      • 412 Posts
      I can’t help you with the code, but your idea is a good one. You would need a chunk or snippet that would basically take the;

      current timestamp - publish date = x
      ’new’ doc period = y
      if x < y show new icon
      else show spacer / nothing

      fairly simple actually.. just need a common denominator for the timestamps and a ’new’ graphic, and someone to help you code.. got the logic out of the way for ya smiley

        • 10449
        • 956 Posts
        this thread might help: http://modxcms.com/forums/index.php/topic,16273.0/topicseen.html
        using Ditto-filters
        http://ditto.modxcms.com/files/snippet-ditto-php.html#filter

        For the new items, you could e.g. just use a special CSS class with a background-image
          • 18397
          • 3,250 Posts
          <?php
          $y = strototime('+'.$number_of_days.'days',$date);
          if (time() < y$) {
          return $modx->getChunk($icon);
          } else {
          return  '';
          }
          ?>
          

          Note: code not tested. Parameters include &number_of_days which must be greater than 1, &date which should be [+createdon+] (or whatever field you are using to hold the timestamp), and &icon which should be the chunk containing all of the html for your new icon.
            • 2433
            • 2 Posts
            Ho great ! Thanks for your help. I’m rather noob to Modx and I can’t figure how to deal with this code.
            I guess I’ve to create a snippet and a chuck called ’icon’ but what else ?
            regards,
            Auré
              • 18397
              • 3,250 Posts
              Exactly that. Then just call the snippet in your Ditto template (alternate between cached and uncached calls) passing along &date=`[+createdon+]`.