We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21112
    • 156 Posts
    Hi, I hope this hasn’t been answered elsewhere, but I’ve scoured the documentation, wikis, forums etc and haven’t been able to find an answer which I am able to apply to my problem.

    I am building a site which will have an archive of articles which have a specific date (I’ve entered the date into the pub_date field). I am using ditto to present the articles and I need to be able to display a selected number of results by year. I have a box on my page with ALL of 2007 articles, and two other boxes which show the first 5 articles each of 2006 and 2005. I’ve looked at the $filter parameter, but can’t figure out how to get it to filter out all years by one in the pub_date field. What am I missing?

    Thanks so much for your help!
      • 18397
      • 3,250 Posts
      Take a look at the dateFilter extender (and its example use in 0.9.6 in conjunction with Reflect)
        • 21112
        • 156 Posts
        Thanks for your reply, but I’m afraid I need a bit more hand-holding than that. I’ve searched and my frustration is growing, so I’m going to have to swallow my pride and ask for more help. The biggest problem I’m having is finding a "top level" explanation of how it all works and what I need to do, perhaps with examples. In my searching I found:

        This thread, which seems close to explaining, but confuses me because I’m not using wordpress, and I don’t understand how this links with the ditto snippet use, because from my reading it seems that both need to be used?
        http://modxcms.com/forums/index.php/topic,14003.0.html

        The official documentation has no examples and doesn’t explain how to correctly code the snippet, only listing the parameters, and I’m afraid describing them in computer programmer terms, which I find hard to figure out, not being very familiar with programming:
        http://ditto.modxcms.com/files/snippet-reflect-php.html

        The TRAC doesn’t seem to make any mention of reflect at all:
        http://modxcms.com/ditto_trac.html

        The compiled documentation for Ditto has been a fantastic resource, but only makes mention of reflect in passing:
        http://modxcms.com/forums/index.php/topic,13533.0.html

        I tried the MODx wiki, but that doesn’t seem to have anything about reflect:
        http://wiki.modxcms.com/index.php/Ditto

        I really have tried to do the research but having as little knowledge of php as I do, I feel like I’m lost in the woods. A simple tutorial would be a huge help, and I’m ahppy to figure it out myself, but I feel like I’ve jumped in the deep end before I can swim!!

        Sorry for being so helpless, I really appreciate the time you take to help me out.
          • 18397
          • 3,250 Posts
          Your are not helpless at all. You’ve perfectly followed the policy on how to get help. smiley The documentation deficiencies are being addressed with a MODx based support site to be unveiled in the near future. If you’d like a sneak peek PM me.

          This should get your started:
          1. Add &extenders=`dateFilter` &dateSource=`pub_date` to your uncached ( [! syntax ) Ditto 2 call
          2. Append &year=YEAR to your URL or send via POST

          Ditto will do the rest wink
            • 21112
            • 156 Posts
            Thanks for your ongoing help!

            I’ve added &extenders=`dateFilter` to the ditto call. I already was using the correct &dateSource. I don’t follow what you mean by "uncached ( [! syntax )". I’m also not sure what you meant in point 2. My ditto call is embedded within a page, and that page will have three different ditto calls, showing documents from 3 different years, so the filter will need to be different on the same page. That, I assume, would mean that putting the &year parameter in the url wouldn’t work. I’m not sure how I can put a "POST" into the ditto call?

            This is the (first) ditto call on my page as it is now:

            [[Ditto? &tpl=`dittospeeches` &parents=`17` &dateSource=`pub_date` &dateFormat=`%d %b %g` &sortBy=`pub_date` &display=`999` &extenders=`dateFilter`]]


            This is the page as it looks now: http://www.orionvisuals.com/wip/harryjenkins/index.php?id=4

            This is a screencap from the designer I’m working with showing how he wants this page to look (some aspects of the design have changed since this stage but the layout is the same):

              • 18397
              • 3,250 Posts
              For uncached syntax I mean calling Ditto like so: [!Ditto!] instead of [[Ditto]].
              To handle the multiple Ditto calls on the same page add &id=`UNIQUE STRING` to each Ditto call where UNIQUE STRING is unique for each call.
              Lastly, add &UNIQUE STRING_year=`2006` where UNIQUE STRING is the same as above for the corresponding Ditto call you want to affect and 2006 is the year you want to show.
              If you want to be able to do this without adding things to the URL file a feature request using TRAC (link in my signerature).
                • 21112
                • 156 Posts
                Okay, I’ve given that a try, here’s what my Ditto call looks like now:

                [!Ditto? &tpl=`dittospeeches` &parents=`17` &dateSource=`pub_date` &dateFormat=`%d %b %g` &sortBy=`pub_date` &display=`999` &extenders=`dateFilter` &id=`speeches2007` &speeches2007_year=`2007` !]


                Unfortunately, it hasn’t filtered out items older than 2007: http://www.orionvisuals.com/wip/harryjenkins/index.php?id=4

                My first guess is that &speeches2007_year=`2007` is looking to the creation date for the year, when i want it to look to the pub_date. All of the items will be created in 2007, so fot items that were originally created in past years, i’ve set their date in the pub_date field. Is there any way to get &speeches2007_year=`2007` to look in pub_date?
                  • 18397
                  • 3,250 Posts
                  You need to add &speeches2007_year=2007 to the URL, not the Ditto call. If you do, it works on that page.

                  Quote from: Mark at Apr 29, 2007, 01:20 PM

                  If you want to be able to do this without adding things to the URL file a feature request using TRAC (link in my signerature).
                    • 25420
                    • 74 Posts
                    Hi,

                    I have the same problem. My call is the following:

                    [!Ditto? &tpl=`ListNews` &parents=`58` &dateSource=`NewsDate` &dateFormat=`%d/%m/%Y` &sortBy=`NewsDate` &display=`999` &extenders=`dateFilter` &id=`allnews` !]
                    


                    my tv is called NewsDate

                    I tried to put &NewsDate=2006 in the url, didn’t filter. I tried &NewDate_year=2006, not working neither. Any idea ?

                    thanks,

                    Seb
                      • 18397
                      • 3,250 Posts
                      @roki13: The URL format is id_year=2006 where ID is what you have set &id to.

                      @all: The development version should now allow you to do this via parameters. For example:
                      [!Ditto? &parents=`2` &extenders=`dateFilter` &dateSource=`createdon` &year=`2006`!]
                      


                      You can get the development version here