We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1330
    • 79 Posts
    I had asked about this about a year ago and got a partial answer but never was able to implement it.  I have 7 pages Monday-Sunday that I would like to change with the day of the week, e.g. ID=33 on sunday, ID=36 on monday, etc.
    Can someone aid me in figuring how to do this. I know you have to create an array to do it but not sure what you do or the syntax.
    $10.00 via Paypal to whoever can get it up and going for me, or get me the info to do it myself.
      • 4041
      • 788 Posts
      Try this and see if it works, tested on 0963

      <?php
      /*    Content_Change_Daily
      
            usage:
            create a new snippet with this code
            set the document id's below to correspond to the days
            add the snippet call to the page content where you want the content to change
            [!Content_Change_Daily!]
      */
      // document id's configuration
      // fill in the id's of the docs you want to display on certain days
      // overall default fallback
      $defaultID ='32';
      
      $sundayID ='';
      $mondayID ='32';
      $tuesdayID ='';
      $wednesdayID ='';
      $thursdayID ='';
      $fridayID ='';
      $saturdayID ='';
      
      // no edit below here
      $output ='';
      
      //===== Date settings ========/
      $todays_details = getdate();
      $lseconds =    $todays_details['seconds'];
      $lminutes =    $todays_details['minutes'];
      $lhours   =    $todays_details['hours'];
      $lmday    =    $todays_details['mday'];
      $lwday    =    $todays_details['wday'];
      $lmon     =    $todays_details['mon'];
      $lyear    =    $todays_details['year'];
      $lyday    =    $todays_details['yday'];
      // this is the only one we use so far
      $lweekday =    $todays_details['weekday'];
      $lmonth   =    $todays_details['month'];
      
      switch ($lweekday){
      case '': $grabID =$defaultID;
      break;
      
      case 'Sunday': $grabID =$sundayID;
      break;
      
      case 'Monday': $grabID =$mondayID;
      break;
      
      case 'Tuesday': $grabID =$tuesdayID;
      break;
      
      case 'Wednesday': $grabID =$wednesdayID;
      break;
      
      case 'Thursday': $grabID =$thursdayID;
      break;
      
      case 'Friday': $grabID =$fridayID;
      break;
      
      case 'Saturday': $grabID =$saturdayID;
      break;
      
      default : '';
      return;
      }
      
      if($grabID =='' || $grabID =='0'){
          $grabID =$defaultID;
      }
      $sql = "SELECT content FROM ".$modx->getFullTableName( 'site_content' )." WHERE id='".$grabID."'";
      $result = $modx->db->query($sql);
      $numrows = $modx->recordCount($result);
      if($numrows==1) {
          $getcontent = $modx->fetchRow($result);
          $output .=$getcontent['content'];
      
          // uncomment the following lines for debug
          //$output .='<br>grabID: '.$grabID;
          //$output .='<br>weekday: '.$lweekday;
      }
      
      unset($grabID);
      return $output;
      ?>


      Hope it helps smiley
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 1330
        • 79 Posts
        Would I add this to each page? To get the page to change?
          • 4041
          • 788 Posts
          No, just add the snippet call to the content area of the base page(can be any page), the content of the base page will then change dynamically depending on what day it is and what document id you have set for that day in the top of the snippet.
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 1330
            • 79 Posts
            I want the front page ( landing page) to change with the day of the week. not just partial content. I need the whole thing to change. E.g Today Start page is 1 tomorrow I need it to be 3.
              • 4041
              • 788 Posts
              OK, this snippet will redirect you to the appropriate page based on the id you set for that day.

              <?php
              /*    Page_Change_Daily
              
                    usage: snippet checks the day and redirects to appropriate page
                    
                    create a new snippet with this code
                    set the document id's below to correspond to the days
                    add the snippet call to the page content or to the top of the template
                    [!Page_Change_Daily!]
              */
              // document id's configuration
              // overall default fallback
              $defaultID ='32';
              // fill in the id's of the docs you want to redirect to on certain days
              $sundayID ='';
              $mondayID ='32';
              $tuesdayID ='';
              $wednesdayID ='';
              $thursdayID ='';
              $fridayID ='';
              $saturdayID ='';
              
              // no edit below here
              $output ='';
              
              //===== Date settings ========/
              $todays_details = getdate();
              $lweekday =    $todays_details['weekday'];
              
              switch ($lweekday){
              case '': $grabID =$defaultID; break;
              case 'Sunday': $grabID =$sundayID; break;
              case 'Monday': $grabID =$mondayID; break;
              case 'Tuesday': $grabID =$tuesdayID; break;
              case 'Wednesday': $grabID =$wednesdayID; break;
              case 'Thursday': $grabID =$thursdayID; break;
              case 'Friday': $grabID =$fridayID; break;
              case 'Saturday': $grabID =$saturdayID; break;
              default : '';
              return;
              }
              
              if($grabID =='' || $grabID =='0'){
                  $grabID =$defaultID;
              }
              if($grabID != $modx->documentObject['id']){
                 $url =$modx->makeURL($grabID);
                 $modx->sendRedirect($url,0,'REDIRECT_REFRESH');
              }
              ?>


              :) if this isn’t what you need, I’m sure someone else will chime in with a better suggestion
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 1330
                • 79 Posts
                Okay so again, do I add this snippet to each of the M-S day pages or do I need to make like a quick load landing page for this to work?