We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17883
    • 1,039 Posts
    Hi all,

    I tried to implement a blog with displaying the number of comments under each entry (summary) like on modx blog. But I think I´ve missed something. Could someone please post the actual call for newslisting including the call for the UserCommentsCount?

    What I´ve tried:

    [[NewsListing? &tpl=`newslisting` &startID=`17` &comments=`true` &commentschunk=`FormBlogComments`&dateformat=`%d-%m-%y %H:%M`]]

    and put in the newslisting chunk (tpl) the [+UserComments.Count+] placeholder, but that didn´t work. Uncached also didn´t work.

    I also played around with the UserCommentsCount snippet by Mark, but I think this is obsolulete because it seems to be integrated in UserComments (see placeholder above). Am I wrong?

    I read this here on the usercomments page:

    Notes:
    If you are using the NewsListing snippet and are not calling UserComments in the template be sure to wrap it in a chunk so that they can be properly filtered out of NewsListing.

    I think there is my problem in understanding this sentence. Can someone give me a hint how this is supposed to look like?

    Thx in advance,

    Marc
      • 25663 MODX Staff
      • 12,272 Posts
      What that means is that the UserComments part in Newslisting should be made in a chunk. That way, the Newslisting snippet itself will remove the call before outputting it to the summary pages listing view.

        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 17883
        • 1,039 Posts
        Hi Ryan,

        thanks for answer. But I think I misunderstand something generally. Could you explain how it works on the modx blog?

        Do you mean to put the Usercomments-Snippet call in a chunk and then insert this chunk in the newslisting template? Can´t try it now sad

        I think I´m totally on the wrong track. What I actually need is a newslisting call with let´s say 10 News/blog entries which show the number of comments (and the link to them) beside each readmore link.

        Thx in advance!

        Marc

          • 22221
          • 283 Posts
          I’ve just find the solution on the French section an by private message with Guillaume,

          I think that work in this way :

          • NewsListing Snippet allow you to list the news tongue. The parameters about comment of this snippet is to avoid the comments to be listed by NewsListing
          • If you want UserComment activated in you news, you have to add a chunck or directly the UserComments Snippet in each document or in the template of the document
          • If you want the count of comment (like the Modx Blog) you have to insert the following line in the chunck used by NewsListing :
          [[UserCommentsCount? &docid=`[+id+]`]]


          I hope this help you
            • 25663 MODX Staff
            • 12,272 Posts
            Mark (NewsListing’s author) will be able to give a great example of that very soon. In the meantime, here’s our main blog page content:
            <?php
            <div id="nl_wrapper">
               [[nl? &startID=`254` &tpl=`nl_blog_tpl` &summarize=`5` &commentschunk=`FormBlogComments` &paginate=`1` &dateformat=`%d-%b-%y` &alwaysshow=`1` &truncText=`Read more...` &multilevel=`1` &filter=`hidemenu, 0|parent, 254,2`]]
            </div>
            
            <div class="nl_paging">Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles<br />
              <div id="nl_pages"> [+previous+] [+pages+] [+next+] </div>
            <!-- close .nl_paging -->
              <a href="[~274~]?id=[*id*]" style="border-bottom: medium none; float: right; margin-right: -1em; margin-top: -25px;"><img border="0" src="http://modxcms.com/assets/images/greenzi/icons/rss.jpg" alt="RSS feed icon" /> </a>
            </div>
            ?>


            Here’s our Newslisting Template:
            <?php
            <div class="nl_article">
              <h3 class="nl_title">
                <span class="nl_info">   <strong><a href="[~[+parent+]~]">[+author+]</a></strong> on [+date+]</span><a href="[~[+id+]~]">[+title+]</a> 
              </h3>
            
              [+summary+]
            
              <p class="nl_link"><a href="[~[+id+]~]#comments">Comments ([!UserCommentsCount?docid=[+id+]!])</a> | [+link+]</p>
            </div>
            ?>


            Here’s our comments chunk template:
            <?php
            <a name="comments" id="comments"></a>
            <p class="BlogMeta">
            <strong>Meta:  </strong><a href="[~274~]?id=[*parent*]"> <img src="assets/images/greenzi/icons/blog-feed.jpg" alt="RSS feed" /> </a> <a href="[(site_url)]index.php?id=[*id*]"> <img src="assets/images/greenzi/icons/blog-permalink.jpg" alt="Permalink" /> </a> 
            </p>
            
            <p><strong>Comments: </strong></p>
            
            <div>
            [!SMF_UserComments? &makefolder=`1` &formtpl=`commentForm` &sortorder=`0` &freeform=`1` &displaytpl=`comment` &postcss=`comment` &titlecss=`commentTitle` &numbercss=`commentNum` &altrowcss=`commentAlt` &authorcss=`commentAuthor` &ownercss=`commentMe` &dateformat=`%d-%b-%y %I:%M %p` !]
            
            </div><br />
            
            [+UserComments.Form+]
            ?>


            And our UserCommentsCount snippet:
            // Comment count by Mark Kaplan
            			
            			$docid = isset($docid) ? $docid : $modx->documentObject['id'];
            			
            			// get folder id where we should store comments 
            			// else store in current document
            			$folder = isset($folder) ? intval($folder):$docid;
            			
            			// set splitter
            			$splitter = '<!--Comment-Spliter:'.$docid.'-->';	
            
            		// get tagid
            			$tagid = isset($tagid) ? preg_replace("/[^A-z0-9_\-]/",'',$tagid):'';
            			
            			// set alias name of document used to store comments
            			$alias = 'usrcmt-'.$docid.($tagid ? '-'.$tagid:'');
            
            			// get comments
            			$ds = $modx->db->select('content',$modx->getFullTableName('site_content'),' parent=\''.$folder.'\' AND alias=\''.$alias.'\'');
            			$content = $modx->db->getValue($ds);
            			// split content into separate comments
            			$parts = explode($splitter,$content);
            			array_pop($parts);
            			// count comments
            			$count = count($parts);		
            			return $count;
            ?>


            Sorry for the long post but I hope it proves to be insightful. Lots of changes and tweaks will be happening to the above soon I suspect, too. wink
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 17883
              • 1,039 Posts
              AAAAAAAAAAAAAAAAARGH rolleyes

              Call me stupid...

              Thank you both for your help. I already played around with all kinds of combinations of chunks/templates/snippet calls, but it didn´t work. At least I had a eval code() error. So I took the snippet UserCountComments posted by you, Ryan and it worked (after deleting the "?>"). So it seems to be an error on this page (download code).

              Thank you so much for your efforts. Hope to make progress this night with building my blog wink

              Marc
                • 15987
                • 786 Posts
                Thanks for putting this out there, I have been trying to figure this out for a while now too.
                  • 18397
                  • 3,250 Posts
                  There seems to be an issue with certain character being stripped out of the snippets on that page. I am going to move both of those snippets to the forums until I can figure out the exact problem.
                    • 18397
                    • 3,250 Posts
                    I posted the uncorrupt files in the forums earlier (but missed mentioning it in this topic) and the blog post now links to them. Please redownload from there and let me know if you have better luck.
                      • 8471
                      • 333 Posts
                      Hi, I have used all this fantastic snippets and chunks, but if I use &multilevel=`1` in the call of NewsListing (that is the same of Mark’s call) I receive a Parse error:
                      « MODx Parse Error »
                      MODx encountered the following error while attempting to parse the requested resource: 
                      « PHP Parse Error » 
                        
                      PHP error debug 
                        Error:  Invalid argument supplied for foreach()   
                        Error type/ Nr.:  Warning - 2   
                        File:  C:\sito\manager\includes\document.parser.class.inc.php(713) : eval()'d code   
                        Line:  388   
                        
                      Parser timing 
                        MySQL:  0.0291 s s (6 Requests) 
                        PHP:  0.4317 s s   
                        Total:  0.4608 s s   
                      

                      Anybody can say me why?
                        Sorry for my bad English grin