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

    I want to display a message on the homepage of my new ModX site saying "This site was last updated on [Day] at [Time]".

    Is there a simple way to do this in ModX?

    All help welcome.

    Cheers
    Smaavie
      • 16610
      • 634 Posts
      GetTime snippet is simple: http://modxcms.com/GetTime-0.html
      And very easy to modify too.
        Mikko Lammi, Owner at Maagit
        • 27680
        • 23 Posts
        Many thanks for telling me about the GetTime - it is almost perfect for my current purposes.

        It seems to me that the GetTime snippet is ideal for displaying, on any given page, the date that this page was updated. However, I need a ’site-wide’ last updated date/time ... i.e. I need to show, on all pages, the date/time that the most recently updated page was updated.

        I hope you can help.

        Cheers
        Smaavie
          • 27376
          • 576 Posts
          Quote from: smaavie at Jul 23, 2007, 08:08 AM

          However, I need a ’site-wide’ last updated date/time ... i.e. I need to show, on all pages, the date/time that the most recently updated page was updated.
          You mean you want a sort "Recently Updated" List of documents on one page? Or you want on each page a timestamp of when that page was updated?

          If it’s the later, then just put the snippet call in your template and it will show up on all of your pages that use the template.
            • 27680
            • 23 Posts
            sirlancelot,

            In short, I want to display the day/time that the most recent update was made to page that was most recently updated. (I hope that makes sense).

            My plan is to put the snippet call into my template so that this value is shown on every page, in the form "This site was last updated on [Day] at [Time]".

            Crucially, the same value should be displayed on all pages. (I don’t want to show the day/time when the current page was last update, I want to show the day/time when the last update was made to any page in the site).


            I hope this clarifies my requirements a bit. Again, any advice would be appreciated.

            Cheers
            Smaavie


              • 28215
              • 4,149 Posts
              Snippet "UpdatedOn":

              <?php
              $ar_tv = $modx->getTemplateVar('UpdatedOn');
              
              if ($ar_tv['value'] == 1) {
               $updated = $modx->documentObject['editedon'];
               $u = strftime("%B %e, %Y",$updated);
               $output = "<div id='updated_on'>Last updated on ".$u."</div>";
              }
              
              return $output;
              ?>
              


              And a TV:

              Name: UpdatedOn
              Input Type: Dropdown List Menu
              Input Option Values: Yes==1||No==0
              Default Value: 1



              Then all you have to do is put this into a template: [[UpdatedOn]]

              And you can specify on individual pages whether or not you want it.

                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 27680
                • 23 Posts
                Hi splittingred

                Thanks for the snippet. It worked without any problems at all, but it didn’t produce exactly the results I require.

                The snippet shows the day/time that the current page was last updated. What I need is just one site-wide value for the day/time of the very last update, regardless of what page it was that was updated last.

                (Sorry if this is not making any sense).

                Cheers
                Smaavie
                  • 27680
                  • 23 Posts
                  ganeshXL,

                  Thanks so much for posting the snippet. It works perfectly, and produces exactly the results I want.

                  I really appreciate your help.

                  Cheers
                  Smaavie
                    • 33337
                    • 3,975 Posts
                    Hey ganeshXL, care to put this nice little snippet in the repo?

                    thanks.
                      Zaigham R - MODX Professional | Skype | Email | Twitter

                      Digging the interwebs for #MODX gems and bringing it to you. modx.link
                      • 14050
                      • 788 Posts
                      And along the similar lines I created this awhile ago for someone:

                      http://cmssandbox.com/MODx095/index.php?id=58

                      It is a snippet that will tell when the last page was created, sitewide. It was posted to the forums back in March.

                      <?php
                      /*
                      ::::::::::::::::::::::::::::::::::::::::
                       Snippet name: LastCreation
                       Short Desc: Lists the time from the last creation of a document
                       Version: 1.0.0
                       Author: Jesse Rochman (Jesster444)
                      	
                       Date: March 7, 2007
                       
                       Example Usage:
                       
                       [!LastCreation!] - Outputs the the time in xx Days xx Hours xx Minutes.  It will return the time of creation for the last document created, regardless of published status.
                       [!LastCreation? &lcPublished=`1` &lcParent=`10`!] - Outputs the time of creation for the last published document created that is a child of document 10.
                       
                       Parameters:
                       &lcPublished: (0|1)
                      If set to 0 it will output the time for the last creation of an unpublished document, if set to 1 it will output the time for the last creation of a published document.
                      
                      &lcParent:
                      The parent ID of the folder you want to look in for last creation times.  Can be used in conjuction with $lcPublished.
                       
                      ::::::::::::::::::::::::::::::::::::::::
                      */
                      
                      if (isset($lcPublished) && $lcPublished < 2) {
                      	$SQL = "published=$lcPublished";
                      	}
                      	else $SQL = '';
                      
                      if (isset($lcParent) && $SQL) {
                      	$SQL .= " AND parent=$lcParent";
                      	}
                      	elseif (isset($lcParent) && !$SQL) {
                      	$SQL = "parent=$lcParent";
                      	}
                      
                      
                      $table = $modx->getFullTableName("site_content");
                      
                      $results = $modx->db->select("createdon", $table, "$SQL", "createdon DESC", "1");
                      
                      $results = $modx->db->getRow($results);
                      
                      
                      $createdon = $results['createdon'];
                      
                      if ($createdon) {
                      	$now = time();
                      	$diff = $now - $createdon;
                      	$days = floor($diff/86400);
                      	$hours = floor($diff/3600);
                      	$minutes = floor($diff/60);
                      
                      
                      	if ($days > 0) {
                      		if ($days == 1) $output = $days . ' day ';    
                      		else $output = $days . ' days ';
                      
                      		$diff = $diff - ($days * 86400);
                      		$hours = floor($diff/3600);
                      
                      	} 
                      	if ($hours > 0) {
                      		if ($hours == 1) $output .= $hours . ' hour ';
                      		else $output .= $hours . ' hours ';
                      	
                      		$diff = $diff - ($hours * 3600);
                      		$minutes = floor($diff/60);
                      	}
                      	else $minutes = floor($diff/60);
                      	if ($minutes >0) {
                      		if ($minutes == 1) $output .= $minutes . ' minute';
                      		else $output .= $minutes . ' minutes';
                      	}
                      
                      	return $output;
                      }
                      else return '';
                      ?>


                        Jesse R.
                        Consider trying something new and extraordinary.
                        Illinois Wine

                        Have you considered donating to MODx lately?
                        Donate now. Every contribution helps.