Sharepoint 2013

Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

Sharing is Caring

I was having an issue to retrieve latest posts from newsfeed,lets say take 5 of them.Tried everything,but newsfeed webpart didnt support filtering according to my need.

So i tried a “css-trick” code i found over the internet and improved it to my needs:

function get5posts() {
$(".ms-microfeed-seeMoreThreadsDivContainer").hide();
var limit = 5;
$("#ms-feedthreadsdiv .ms-microfeed-thread").each(function (i) {
if (i >= limit) {
$(this).addClass("ms-hide");
}
});
}

The code above shows only 5 posts on page load.But what happens if you add more in newsfeed? The 5 item limit exceeds and you need to call a function to restrict it to 5 item:

Call get5posts() in page load event:

$(document).ready(function (e) {
get5posts();
});

Afterwards call it again if user clicks on post reply button:

$("#ms-postbutton").on("click", function () {
get5posts();
});

This will limit NewsFeed to 5 posts only.

Nice Trick!