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!

Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013” üzerine 5 yorum

    1. Hi Marin,

      The only code I’ve written was a seperate Javascript file referenced via Masterpage.

      You can add NewsFeed/SiteFeed webpart to your portal,the usual way(Edit->Add WebPart)
      And then,
      the javascript code explained above shall do the rest for you.

      Hope that solves your problem.

      1. If you want to use your own custom design,best approach would be a custom webpart which retrieves post from Newsfeed/SiteFeed list or retrieving posts via rest api/webservice.I’ve worked with rest api but dont know if it allows you to retrieve them.

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir