We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12151
    • 115 Posts
    greetings ...

    i am using Jot to gather customer comments on a client’s website, with custom fields, moderation and badwords, etc. however the client then asked for a random comment to be shown in a box on the homepage. i couldn’t find anyway of getting Jot to do this so after reading through documentation and code of other snippets i came up with the following snippet. it works perfectly, but I’m sure there is a better, more elegant/efficient way of doing this. i’m a sucker for efficient code, but i don’t know PHP or the inner working of MODx well, so does anyone want to offer some suggestions? cheers!

    <?php
    $rsContent = $modx->db->select("id,content", "modx_jot_content", "published=1", "RAND()", "1");
    $arr = mysql_fetch_array($rsContent);
    $id = $arr['id'];
    $content = $arr['content'];
    
    $rsFields = $modx->db->select("content", "modx_jot_fields", "label='name' AND id=".$id);
    $arr = mysql_fetch_array($rsFields);
    $name = $arr['content'];
    
    $rsFields = $modx->db->select("content", "modx_jot_fields", "label='location' AND id=".$id);
    $arr = mysql_fetch_array($rsFields);
    $location = $arr['content'];
    
    $strReturn = "<div id='TestimonialHighlightCopy'>".$content."</div><div id='TestimonialHighlightCredit'>- ".$name.", ".$location."</div>";
    
    return $strReturn;
    ?>
      • 2912
      • 315 Posts
      I came across this old post and decided to use it. It has come in very handy:

      http://modxcms.com/forums/index.php/topic,16147.msg103290.html#msg103290
        BBloke
        • 18331
        • 20 Posts
        Maybe someone could post the code for limiting character number and placing "..." at the end if comment is longer than x characters.

        Thanks for your help!
          • 12151
          • 115 Posts
          This post is really old now, but these days I usually just use the jQuery ThreeDots scripts to achieve what you’re after:
          http://tpgblog.com/ThreeDots/

            • 18331
            • 20 Posts
            Thanks for your reply. I’m newbie in programming. Could you modify that source above with threedots jquery? Thank you very much in advance.
              • 12151
              • 115 Posts
              Please note that this code snippet was created for v0.9.x two years ago and probably will not work as is in the latest 2.0 version (I have not used Revolution yet so I don’t know what syntax changes would need to be made). That said, here’s the code with ThreeDots implemented as requested. I have not tested this code but it should work fine, reducing the copy to 2 lines maximum. This assumes you have jQuery and the ThreeDots scripts in place in your <head>.

              <script type="text/javascript">
              $(document).ready(function() { 
                $('#TestimonialHighlightCopy').ThreeDots({ 
                 max_rows:2,
                 alt_text_t:true
                });
              });
              </script>
              
              <?php
              $rsContent = $modx->db->select("id,content", "modx_jot_content", "published=1", "RAND()", "1");
              $arr = mysql_fetch_array($rsContent);
              $id = $arr['id'];
              $content = $arr['content'];
              
              $rsFields = $modx->db->select("content", "modx_jot_fields", "label='name' AND id=".$id);
              $arr = mysql_fetch_array($rsFields);
              $name = $arr['content'];
              
              $rsFields = $modx->db->select("content", "modx_jot_fields", "label='location' AND id=".$id);
              $arr = mysql_fetch_array($rsFields);
              $location = $arr['content'];
              
              $strReturn = "<div id='TestimonialHighlightCopy'><span class='ellipsis_text'>".$content."</span></div><div id='TestimonialHighlightCredit'>- ".$name.", ".$location."</div>";
              
              return $strReturn;
              ?>
              
              
              

                • 18331
                • 20 Posts
                Thank you very much for your help! You saved me a lot of time! I’m using modx 1.0.4, so it works perfectly!

                Thank you once again!!!:)
                  • 12151
                  • 115 Posts
                  You’re most welcome dude smiley
                    • 18331
                    • 20 Posts
                    One more question. How should i modify the source to select from which ID random jot comments should be taken?
                      • 12151
                      • 115 Posts
                      I would imagine the easiest way would be to change the WHERE clause of the first SELECT thus:
                      $rsContent = $modx->db->select("id,content", "modx_jot_content", "uparent=".$docid." AND published=1", "RAND()", "1");

                      This of course assumes you know the ID of the document from which you want to retrieve a random comment.