We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1122
    • 209 Posts
    In several threads around this forum I helped people with rendering latest comments which appeared to be a painful issue.
    Recently I have rewritten/generalized the code used for such rendering by adding templating feature, date formats, etc.

    Download: http://setpro.pl/download.php?item=latestcomments.txt
    Small article: http://setpro.pl/software/latest-comments

    Some guidelines on how to use this snippet have been included into its header. I am pasting those instructions here...
    Parameters:
    parents - which container(s) to fetch the comments from (default: 0, entire site)
    count - how many latest comments to fetch (optional; default: 6)
    customFields - comma-separated list of custom fields (optional; default: name,email)
    posterField - poster’s field name (optional; default: name)
    dateFormat - PHP’s date() format for createdon, editedon fields (optional; default: Y-m-d, H:i:s)
    tplComment - chunk containing template for a single comment (REQUIRED; see example below)
    trunc - at which symbol the comment should be truncated (default: 0, do not truncate)
    truncSym - symbol/string to use for marking truncation (default: ’...’)
    Sample usage:
    [!LatestComments? &count=`3` &customFields=`name,website` &tplComment=`tpl-comment`!]
    Sample template (chunk tpl-comment):
    <div class="poster"><a href="[+jcf_website+]">[+jcf_name+]</a> on [+createdon+] said:</div>
    <div class="post">&quot;[+content+]&quot;</div>
    <div class="link">Read full article <a href="[~[+doc_id+]~]">[+doc_pagetitle+]</a>...</div>
    Comment’s main placeholders:
    [+id+] - internal id of the comment
    [+title+] - self-explanatory
    [+tagid+] - value used to distinguish two (or more) Jot calls on the same page
    [+uparent+] - id of the document that the comment is attached to
    [+secip+] - IP of the remote machine that the comment has been submitted from
    [+content+] - self-explanatory
    [+createdby+] - full name of the author (either MODx user or poster-provided value)
    [+createdon+] - date of the creation (formatted with dateFormat)
    [+editedby+] - full name of the MODx user who latest accessed/changed the comment
    [+editedon+] - date for the above action (formatted with dateFormat)
    [+publishedby+] - full name of the MODx user who published the comment (if in moderated mode)
    [+publishedon+] - date for the above action (formatted with dateFormat)
    Comment’s custom placeholders:
    [+jcf_...+]
    Document’s placeholders:
    [+doc_id+]
    [+doc_pagetitle+]
    [+doc_longtitle+]
    [+doc_description+]
    [+doc_introtext+]
    Important remarks:
    Please notice that placeholders for Jot custom fields SHOULD BE prefixed with "jcf_"
    Both [+uparent+] and [+doc_id+] stand for the same value
      • 26931
      • 2,314 Posts
      hey alik,

      thanks a lot for sharing! j
        • 8609
        • 607 Posts
        Nice! Thank you for sharing smiley
          • 22804
          • 5 Posts
          This is great. Does anyone know how you would include a link to the related document that the comment was made on?
          • Just build a link using the [+uparent+] placeholder:
            <a href="[~[+uparent+]~]">Read article</a>
              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
              • 22804
              • 5 Posts
              sottwell,

              Thanks! Any chance you could help me out with a placeholder for the Title of the article?

              Thanks again,

              Paul
                • 20413
                • 2,877 Posts
                @paulcj72 Try title and content placeholder http://modxcms.com/forums/index.php/topic,47196.0.html
                  @hawproductions | http://mrhaw.com/

                  Infograph: MODX Advanced Install in 7 steps:
                  http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                  Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                  http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                  • 22804
                  • 5 Posts
                  @mrhaw,

                  Whouldn’t that just return the title of the comment and not the title of the parent document?
                    • 20413
                    • 2,877 Posts
                    Ah! I see...
                    1. Download/Install GetField snippet http://modxcms.com/extras/package/173
                    2. [[GetField?docid=`[+uparent+]` &field=`pagetitle`]]

                    //Name it GetField when installing, not getField.
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 1122
                      • 209 Posts
                      2All
                      Obtaining info for a document that the comment is attached to seems to be another painful issue. GetField snippet is a solution, but it actually causes additional pass of MODx parser. Since obtaining document’s info is easily doable within the same "DB touch" as a comment’s info itself I’ve extended my snippet a bit -- please read updates in a first post.