We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19257
    • 141 Posts
    Hi, I’m creating a site in modx and everything’s going awesome. It’s a great system but I’ve been looking around for some info on how to create a [glow=red,2,300]quote of the day feature[/glow] on the site and I haven’t found anything.

    Here’s what I want it to do:


    • Appear in a small section in the front page
    • Update itself with new quotes on the day and hour I specify (like the publish date feature in documents)

    The plan is to have a new quote every day at midnight. It will be the same quote throughout the day, I don’t need it randomized or anything like that.
    Let me know if this is possible, I’m hoping someone can give me some advice! grin

    Josh
      • 33372
      • 1,611 Posts
      You could do this many different ways in MODx, actually. You could create a subfolder with documents for each quote and with publish and unpublish dates and just use Ditto with a limit of one document retrieved to display the current quote. Or you could do a number of other things (such as keeping your quote list in a chunk and using a snippet to choose the current one, or just naming your quote documents by date and using a snippet to load them)...
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 4385
        • 372 Posts
        You could bind a text file to a TV

        Create a text file with a "|" delimiter (Quote one.|Quote two.|Quote three.|Quote etc.)


        Create a TV called something like listitem

        Set the default value to:
        @FILE assets/files/quotes.txt


        create a snippet, such as... [[todaysItem]]

        <?php
        $field = (strlen($listTV)>0) ? $listTV : 'pagetitle';
        $docfield = $modx->getTemplateVarOutput(array($field), $modx->documentIdentifier, 0);
        $listArray = explode("|", $docfield[$field]);
        
        $motd = date("z") % 365;
        
        return $listArray[$motd];
        ?>
        


        call it like this [!todaysItem? &listTV=`listItem`!]

        You can just append quotes to the text file or upload them all at once.

        This might get slow with a large number of quotes. You could put them in to a DB.

          DropboxUploader -- Upload files to a Dropbox account.
          DIG -- Dynamic Image Generator
          gus -- Google URL Shortener
          makeQR -- Uses google chart api to make QR codes.
          MODxTweeter -- Update your twitter status on publish.
          • 3749
          • 24,544 Posts
          I think this might be the easiest (if you have enough quotations):

          Put all the quotations in an unpublished MODx document (one for each day of the year), each prefixed by a tag like:

          #QUOTE# One day’s quotation here.
          #AUTHOR#Name here

          #QUOTE# Another day’s quotation here
          #AUTHOR#Another name here

          etc.

          Then use a snippet to get the document content, "explode" it into an array and then pick today’s quotation based on the day of the year.

          The snippet call would be:
          [[QuoteOfTheDay? &docID=`33`]]


          (replacing 33 with the actual document id of the quotations content document)

          The QuoteOfTheDay snippet would look something like this:

          global $modx;
          $doc = $modx->getDocument((string)$docID, '*', 0); // note: this only looks for unpublished docs
          $docString = $doc['content'];
          $docArray = explode("#QUOTE#",$docString);
          
          $day=intval(date("z"));
          $quote =  $docArray[$day];
          
          $parts=explode("#AUTHOR#",$quote);
          
          $output="<h2>Quote of the day</h2> ";
          
          $output .= '<div class="quotation">';
          $output .= $parts[0];
          $output .= '</div>';
          
          $output .= '<div class="author">';
          $output .= $parts[1];
          $output .= '</div>';
          
          
          return $output;


          Warning: This is off the top of my head and it’s 3:30 am here.

          Bob

            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
            • 33372
            • 1,611 Posts
            This is what I love about MODx and its community: There are always a dozen different ways you can do anything and plenty of people willing to share them with you!
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 4385
              • 372 Posts
              Yes, plenty of choices. Sometimes thats the problem! I wish I smarted enough to which way was the "better" way.

              I would probably not go with the flat file that I suggested. It seems like to much overhead everytime for little quote. I like BobRay’s idea (although I am scared of creating they many documents). I would do it with Ditto (like ZAP said) and it would allow for authors and categories, plus the advantage of turning it into an RSS feed.
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.
                • 33372
                • 1,611 Posts
                Actually, BobRay is suggesting having just one document with all of the quote text in it. With Ditto (my first suggestion) you’d need a document for every quote, which could be cumbersome to add and edit (and a bit slower to process). I might prefer BobRay’s method or the same thing using a chunk to Ditto for that reason.

                Right now I’m going to do something similar using a module with parameter-sharing, so we haven’t even come close to listing all of the possible ways to do this yet!

                But in terms of being helpful to the OP, there really isn’t one "right" way to do what you want. There are many ways - all of which would work - so you can choose what seems to make the most sense to you. Ditto is probably the way that you’ll find the most documentation for (since it’s a standard snippet and there’s a subforum dedicated to it), but if you’re comfortable doing some minor PHP coding you might prefer to write your own more lightweight snippet.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 3749
                  • 24,544 Posts
                  Quote from: ZAP at Feb 22, 2008, 12:19 PM

                  Actually, BobRay is suggesting having just one document with all of the quote text in it. With Ditto (my first suggestion) you’d need a document for every quote, which could be cumbersome to add and edit (and a bit slower to process). I might prefer BobRay’s method or the same thing using a chunk to Ditto for that reason.

                  The method I suggest was cribbed from the EZFaq snippet (so I know it works) and, as you say, only involves one document.

                  The reason I suggested having all the quotations in one doc is that I’ve managed quotation DBs and having each quotation in a different file, db record, or document makes it somewhat annoying when you want to correct or replace quotations. I think this way is also faster and easier for a less knowledgeable user to implement and understand. It’s also pretty easy to modify it to grab a random quotation.

                  There is definitely overhead involved in reading all quotations to get one but, once the quotes are in there, you can make both the doc and the snippet cacheable so it’s not that bad.

                  Bob
                    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
                    • 19257
                    • 141 Posts
                    Very nice! Thanks a bunch for the great amount of support. I really appreciate it, I’ll give those methods a try and I’ll keep you guys posted on the success of the feature.

                    Thanks! smiley

                    Josh
                      • 19257
                      • 141 Posts
                      I’m sorry to keep bothering but I can’t get anywhere with this small task! embarrassed

                      I guess theres something I’m missing.. I want to make each quote on a separate document so I can publish them on the day I want with Ditto.

                      I created some quotes, one on each document, and I placed them under a parent folder (quotes) but I’m stuck..

                      I need to know the following:


                      • Do I need to create a snippet or a tv?
                      • What do I need to place as a chunk in the template?
                      • Do I need to place anything in the "homepage" document where I want the quotes to appear?
                      • What do I place in the parent folder?
                      • Do I need to place anything in the document containing the quotes, other than the individual quotes?
                      • Last but not least, how do I set up an rss feed for quotes through ditto?

                      I know this must all seem very obvious but its been a couple of hours and I haven’t been able to find anything on the topics in the forum. I hope I’m not being a huge bother! I appreciate ANY help! Thanks a million. smiley