Home › Forums › Comment box for SharePoint › Hide / unhide the CommentBox, display number of custom comments in the homepage
Tagged: hide button, number comments
- This topic has 6 replies, 2 voices, and was last updated 8 years, 9 months ago by William.
-
AuthorPosts
-
-
March 3, 2016 at 10:19 #10578
-
March 4, 2016 at 20:09 #10621
Currently all parts of the comment box instance is not contained in an outer “wrap” so you cannot toggle it easily. I’ll look at this in the next version.
I’m not sure I understand what you mean by customizing the comment count display – can you add a picture as an attachment?
Alexander
-
March 9, 2016 at 07:30 #10699
Dear Alexander,
Sorry for my late reply, I meant this link displaying the number of comments (image attached).
Thank you,
Attachments:
-
March 14, 2016 at 00:03 #10744
Hi,
You can put this code at the bottom of the page from your screenshot above:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script type="text/javascript"> jQuery(".ms-comm-metalineItemSeparator").each(function(i,a){ var b = _spPageContextInfo.webServerRelativeUrl+a.href.split(_spPageContextInfo.webAbsoluteUrl)[1].split("#")[0]; $.ajax({ type:"GET", url:_spPageContextInfo.webServerRelativeUrl+"/_api/web/lists/getByTitle('SPJS-CommentBox')/items?$filter=substringof('"+b+"',Title)", method: "GET", headers: {"Accept": "application/json; odata=verbose"}, success:function(data){ $(a).text(data.d.results.length+" Comments") }, error:function(data){ //console.log(data); } }); }); </script>
Let me know if you have any questions.
Alexander
- This reply was modified 8 years, 9 months ago by Alexander Bautz. Reason: Changed POST to GET
- This reply was modified 8 years, 9 months ago by Alexander Bautz.
-
March 17, 2016 at 10:15 #10784
Dear Alexander,
I have added a CEWP in my Blog homepage and loaded the script you provided, but the number of comments still shows 0.
Can you provide more guidance, please?Thanks for your work,
William
-
March 19, 2016 at 08:53 #10805
Hi,
It looks like the code must be loaded with a slight delay to allow for the original comment count function to finish drawing the part we need to change. Try changing it like this:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script type="text/javascript"> function spjsCommentCount(){ jQuery(".ms-comm-metalineItemSeparator").each(function(i,a){ var b = _spPageContextInfo.webServerRelativeUrl+a.href.split(_spPageContextInfo.webAbsoluteUrl)[1].split("#")[0]; $.ajax({ type:"GET", url:_spPageContextInfo.webServerRelativeUrl+"/_api/web/lists/getByTitle('SPJS-CommentBox')/items?$filter=substringof('"+b+"',Title)", method: "GET", headers: {"Accept": "application/json; odata=verbose"}, success:function(data){ $(a).text(data.d.results.length+" Comments") }, error:function(data){ //console.log(data); } }); }); } _spBodyOnLoadFunctionNames.push("spjsCommentCount"); </script>
Please note that you should not load jQuery more than one time in a page. If you already have this laded – for example in the master page – skip the line form this code example.
Alexander
-
March 21, 2016 at 04:52 #10831
Dear Alexander,
Thank you, it works perfectly !!
-
-
AuthorPosts
- You must be logged in to reply to this topic.