We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5532
    • 251 Posts
    Hey There alik,

    Thanks for the snippet, everything worked great (I forgot to use my own database prefix_ at first). I also wnated to include the poster’s name and tried to do that myself, but as you can see I don’t know any php.

    The name is kept in a different place called: ssb_jot_fields. Is it possible to bring in the names and link them with the comments? Here was my feeble attempt!:
    <?php
    /* scheme for LatestComments snippet */
    
    $count = 3; // how many latest comments
    // fetch latest comments
    $results = $modx->db->select('uparent,title,content,createdon', 'ssb_jot_content', 'published=1', 'createdon DESC', $count);
    // fetch poster's name
    $results = $modx->db->select('content', 'ssb_jot_fields', $count);
    // render output
    $output = '';
    while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
    
      // now use $row['uparent'], $row['title'], $row['content'], $row['createdon']
      // for building your list of latest comments
      // $row['uparent'] -> id of the doc that the comment is attached to
      // $row['title'] -> comment's title
      // $row['content'] -> name of commenter
      // ...
    
      // for example, comment's title as a link to its article
      $output .= '<div class="jot-user">' . $row['content'] . ' SAYS:</div><div class="jot-message"><a href="[~' . $row['uparent'] . '~]">' . $row['content'] . '</a></div>';
    
    }
    return $output;
    ?>
      • 1122
      • 209 Posts
      In order to obtain also poster name (stored in a different table), your query needs to be more sophisticated:
      <?php
      /* scheme for LatestComments snippet */
      
      $count = 5; // how many latest comments
      // use this for fetching comments and poster name
      $query = "SELECT modx_jot_content.*, modx_jot_fields.content AS name " .
          "FROM modx_jot_content " .
          "INNER JOIN modx_jot_fields " .
              "ON modx_jot_content.id = modx_jot_fields.id " .
          "WHERE modx_jot_content.published = '1' AND modx_jot_fields.label = 'name' " .
          "ORDER BY modx_jot_content.createdon DESC " .
          "LIMIT 0, " . $count;
      $results = mysql_query($query);
      // instead of this
      // $results = $modx->db->select('uparent,title,content,createdon', 'modx_jot_content', 'published=1', 'createdon DESC', $count);
      // render output
      $output = '';
      while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
      
        // now use $row['uparent'], $row['title'], $row['content'], $row['createdon']
        // for building your list of latest comments
        // $row['uparent'] -> id of the doc that the comment is attached to
        // $row['title'] -> comment's title
        // ...
        // now you can use also $row['name'] for inserting poster
      
        // for example, comment's title as a link to its article
        $output .= '<div class="..."><a href="[~' . $row['uparent'] . '~]">' . $row['title'] . '</a></div>';
      
      }
      return $output;
      ?>
      

      Remember about correct table prefix.
        • 5532
        • 251 Posts
        Mate, thank you so much - just sent you a wee donation via your site.

        Cheers

        Ben
          • 22804
          • 5 Posts
          Alik,

          I would love to use your snippet, and I understand how to add your code as a new snippet, but what would the call in my site template be?

          something like

          [!LatestComments &parents=`2` .......

          or ?

          Thanks!

          Paul
            • 1122
            • 209 Posts