Monday 15 June 2015

SharePoint 2013 - Show only Top 5 Feed in Newsfeed webpart


By Default SharePoint 2013 Newsfeed webpart shows 10 posts and there is no way to customize the number of posts out of the box.

So here is the cool trick to show only 4 posts instead of 10 using Jquery - Javascript.

<script type="text/javascript">
$(document).ready(function () {
   var limit=4;
   $("#ms-feedthreadsdiv").attr("numHiddenThreads", "6")
   $("#ms-feedthreadsdiv .ms-microfeed-thread").each(function(i){
   if(i>=limit){
          $(this).addClass("ms-hide");
       }
   });
});
</script>

By Setting numHideenThreads attribute value = 6 for the div help you avoid overwriting the "View Posts" link functionality to load rest of the posts.
If you don't set this attribute value, then on click of "View Posts" link, it will just load rest of the posts other than original 10 posts.

Reference: https://social.msdn.microsoft.com/Forums/sharepoint/en-US/0b37455a-904e-47b2-9705-e06d8a7029bd/limiting-the-height-of-site-feed-webpart-in-sharepoint-2013?forum=sharepointdevelopment  

No comments:

Post a Comment