We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20751
    • 122 Posts
    I have a custom "publishdate" variable I use for news and articles for use in Ditto 2.x. I wondered if it were possible to use the custom date variable in RSS output?

    Currently, it seems you can only set it to createdon, pub_date, editedon:

    $GLOBALS["dateSource"] = isset($dateSource) ? $dateSource : "createdon";
    	// date type to display (values can be createdon, pub_date, editedon)
    


    Any help or pointers greatly appreciated!!

    Thanks smiley
      • 18397
      • 3,250 Posts
      Those values are just examples. You can use a tv there without a problem.
        • 20751
        • 122 Posts
        Thanks!

        It works! Next time I’ll just try before asking! grin
          • 20751
          • 122 Posts
          I think I spoke to soon . . . thought it was working, but it isn’t.

          When I substitue this:

          $GLOBALS["dateSource"] = isset($dateSource) ? $dateSource : "createdon";
          	// date type to display (values can be createdon, pub_date, editedon)


          for this:

          $GLOBALS["dateSource"] = isset($dateSource) ? $dateSource : "publishdate";
          	// date type to display (values can be createdon, pub_date, editedon)


          The date reads:

          01 January 1970, 01:00:00


          publishdate, being my custom tv which is assigned to the template the document uses.

          Is there something else besides just dropping in the name of my tv I need to do?

          Thanks!

            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Is your date a Unix timestamp? I believe that’s what the other suggestions are, and the code probably is written to convert a timestamp, and if it’s given something else will produce the default that you’re getting.
              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
              • 18397
              • 3,250 Posts
              If it is not, make sure you enable the "Unixtime" widget.

              Also, you need to set &dateSource as a parameter, not change the snippet, as the tv autodetection will not work. If you need to have this as the default for all Ditto call add
              $dateSource="publishdate";
              

              ...to the default config file.
                • 20751
                • 122 Posts
                Thanks sottwell and mark . . . we’re getting somewhere now.

                I changed the date widget from date formatter to unixtime and the rss feeds dates now work. However, the ditto call that displays my list of news articles and the date they were published using my custom tv [+publishdate+] displays the following on my web pages:

                by Administrator on 1175128126


                instead of

                by Administrator on Wednesday 28 March, 2007


                How do I get the publishdate tv to display a nicely formatted date if the widget is set to unixtime?

                Thanks again for your continued kind assistance!

                  • 11975
                  • 2,542 Posts
                  Hi,

                  you can use PHx modifier in your chunk

                  http://wiki.modxcms.com/index.php/PHx#date.28.3D.60dateformat.60.29

                  [+publishdate:date=`%d %F %Y`+]

                  or define the &dateFormat param in your ditto call

                  :-)
                    Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                    • 20751
                    • 122 Posts
                    Thanks heliotrope!

                    That worked (using the PHx modifier) apart from one small thing . . . %F doesn’t produce a textual representation of the month as described in the PHP manual, instead it produces the following:

                    28 2007-03-28 2007


                    So i switched to the following code:

                    [+publishdate:date=`%d-%m-%Y`+]


                    which gives me:

                    by Administrator on 28-03-2007


                    Which I’m happy with! Any idea why some of the date parameters don’t work with PHx? Is this a limitation of the plugin or something I’m doing?

                    Thanks again! Hours of head-banging-against-brick-walls are now over!

                    PS I’m in the UK so that’s why the dates may be the wrong way round if you’re in the US smiley

                      • 11975
                      • 2,542 Posts
                      Sorry,

                      PHx uses strftime function => http://www.php.net/strftime

                      change your date format to

                      [+publishdate:date=`%d-%B-%Y`+]

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l