We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36519
    • 40 Posts
    I was thinking about automating "New" icon display for article that I am adding to my site. Currently, my production site is non-modx and relatively static, so I simply append the "new.png" at the end of the list item that is new, and remove the icon after a month or so.
    My Prototype site uses modx and also I use getresources to automatically generate the list page. So inside me thinks using the modification date that is available for each resources, I should be able to conditionally add the icon to list items and automate that part. I am thinking something like;

    if today minus modification date is less than 30 days, then show new.png

    It is much appreciated if somebody can direct me as to where to start and general idea of how this can be done using modx utilities. I am comfortable with CSS and javaScript but have still learning PHP (and modx), by the way.
      • 7914
      • 137 Posts
      I did something like this for a non-MODx project. I have quite a bit to learn, so perhaps there is a better way. This worked for me however, so maybe it will help you get started.

      $reminder_date = date( 'Y-m-d', strtotime('-1 year') );
      
      if ($user_profile->modify_date != "" && $user_profile->modify_date <= $annual_reminder)
      {
          // do something
      }
      else
      {
         // do something else
      }
      


      Basically, I am comparing a user’s modify date to today’s date 1 year ago...(I think I said that right)
      So what you could do just like you said is to capture the resource’s publish date and compare that to any given date... if it’s past "x" amount of time, don’t display the new icon.

      This page by Bob Ray is an outstanding resource to help you find the values of things. I think I have that page open all the time when I am working on a MODx project.

      Hope this helps!
        • 36519
        • 40 Posts
        Thank you!
        I think what I want to do is to be able to conditionally insert <img> tag at the end of <li></li> items that getResources generates. Your reference for modX objects will definately help. Now its time to dig in grin
          • 3749
          • 24,544 Posts
          One common way is to put a placeholder on the page for the whole image tag, then set that in your snippet, something like this:

          [[+NewImage]]



          /* snippet code */
          // set $isNew here
          
          if ($isNew) {
              $ph = 'img src="' . $imagePath . '" alt = "something" />'
          } else {
             $ph = '';
          }
          $modx->setPlaceholder('NewImage',$ph);
          
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting