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

    is there anyway I can mark the posts ditto outputs with some sort of new tag?

    Something like: if the post is less that one week old show <span>New</span>

    thanks,
    G

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Should be able to do something along those lines with phx. Ditto comes with PHx so no need to install the plugin, but it works in the same way as the plugin.

      http://wiki.modxcms.com/index.php/PHx

      Possibly something along the lines of comparing the createdon timestamp with a current timestamp - <however many seconds in a week> and displaying an image if it’s greater than or equal to it. Probably need a custom modifier.

      http://wiki.modxcms.com/index.php/PHx#Custom_modifiers

      There are others here far more expert with phx than I am that might be able to give better advice.

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10357
        • 573 Posts
        thanks! looks like that might be the ticket. Is there a modx tag for the age of the document?
          • 20413
          • 2,877 Posts
          Here is an example of what I do (with PHx installed)

          [*pub_date:date=`%d-%b-%y %H:%M`:twitterdate*]


          Then create a snippet: phx:twitterdate
          and paste in this terrific piece of code:
          <?php
          /*
           * JavaScript Pretty Date
           * Copyright (c) 2008 John Resig (jquery.com)
           * Licensed under the MIT license.
           */
          
          // Ported to PHP >= 5.1 by Zach Leatherman (zachleat.com)
          $date = new DateTime($output);
          $compareTo = new DateTime('now');
          
          $diff = $compareTo->format('U') - $date->format('U');
          $dayDiff = floor($diff / 86400);
          
          if(is_nan($dayDiff) || $dayDiff < 0) {
              return '';
          }
                  
          if($dayDiff == 0) {
              if($diff < 60) {
                  return 'Just now';
              } elseif($diff < 120) {
                  return '1 minute ago';
              } elseif($diff < 3600) {
                  return floor($diff/60) . ' minutes ago';
              } elseif($diff < 7200) {
                  return '1 hour ago';
              } elseif($diff < 86400) {
                  return floor($diff/3600) . ' hours ago';
              }
          } elseif($dayDiff == 1) {
              return 'Yesterday';
          } elseif($dayDiff < 7) {
              return $dayDiff . ' days ago';
          } elseif($dayDiff == 7) {
              return '1 week ago';
          } elseif($dayDiff < (7*6)) { // Modifications Start Here
              // 6 weeks at most
              return ceil($dayDiff/7) . ' weeks ago';
          } elseif($dayDiff < 365) {
              return ceil($dayDiff/(365/12)) . ' months ago';
          } else {
              $years = round($dayDiff/365);
              return $years . ' year' . ($years != 1 ? 's' : '') . ' ago';
          }
          ?>


          This output how long time ago since published.
          You can use [*createdon*] the same way. // when first created

          // In Ditto tpl chunk use [+ +] instead of [* *]
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 10357
            • 573 Posts
            thanks to both of your help I have got this working.

            here’s what I did:

            Chunk newTag
            <span class="new">New</span>


            Snippet phx:postAge
            <?php
            $date = new DateTime($output);
            $compareTo = new DateTime('now');
            
            $diff = $compareTo->format('U') - $date->format('U');
            $dayDiff = floor($diff / 86400);
            if($dayDiff < 1) {
                return '{{newTag}}';
            }
            ?>
            


            And in my ditto template:

            [+createdon:date=`%d-%b-%y %H:%M`:postAge+]
            


            many thanks,
            G