Posted in Sharepoint 2013

Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

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!

Advertisements

5 thoughts on “Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

    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. OK, thx.. thats simpl but i need something like “last X comments” but in custom design..

      2. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s