6

I am trying to duplicate the default Blog Posts web part that is created for Blog sites on SharePoint 2013. Finding that it is not a simple things though I would guess that many others would be looking to do this too. Does anyone have any information that could assist me with this endeavor? I'm trying to put this in a homepage for a publishing site.

Edit: Here is a screenshot from a SharePoint 2013 OOB Blog site and basically what I want to put on a publishing site. I was able to get the blog lists on the site through this blog, now I just need the left-hand side webpart. enter image description here

  • what is the purpose of the webpart? showing the blog post on home page or something else? – Waqas Sarwar MVP May 8 '15 at 20:01
  • Yeah, to show a feed of the most recent blog posts with the ability to like, comment, and email. Just like the one on the default.aspx page when you create a blog site. – Christopher May 9 '15 at 18:53
1

You can use the OOTB blogs list-view webpart. But you also need to add categories listview webpart and blog tools to make it work.

->Add a webpart
->select Apps->Posts
->edit the webpart select "summary view" in view dropdown
->add categories listview webpart in the same way and "change the vieww to "summary view".
->Add blog tools webpart from Blog section of webpart menu.

Adding only the "blog posts" webpart to Page does not work.

You cannot style the OOTB webpart in all the cases, the markup generated by this generally will be in like <li>tags in <ul> tag, but unfortunately, SharePoint renders the markup in different way based on the content inside the blog posts, In my case, it rendered the markup like UL->DIV->LI(you cannot really predict how it is going to render) and it was very hard to style it the way I wanted. I did the same way as @Christopher did using angular JS. Or you can also use a search result webpart(with custom display templates), if you need a pagination like PREV 1,2,3... NEXT (not just prev|next)

0

Well I don't think you are going to be able to use the built in web part, as it references the lists on the blog subsite. What we did to solve this, was to use a content Query webpart with custom XSL to change the layout.

Here are some links:

Blog Post with good Explanation

or just do a google search: https://www.google.de/search?q=sharepoint+content+query+webpart+custom+xsl

We just setup the content query on our blog posting list and changed our xsl query and custom css to look like we wanted it to. Since we just wanted an overview, our XSL wouldn't fit for you. But if you need more info, I would be glad to post our XSL example.

0

It's a long mess but eventually I got a solution through a custom App Part and angular. It definitely needs some more help before I'll be happy with it but it is functional. Here's a good start point for people. If someone wants to add to it please post a link here. I'll do it when I can.

"use strict";
window.Communica = window.Communica || {};

var app = angular.module('blogPart', []);

function getQueryStringParameter(paramToRetrieve) {
    var params;
    var strParams;

    params = document.URL.split("?")[1].split("&");
    strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == paramToRetrieve)
            return singleParam[1];
    }
}
(function (angular) {
    'use strict';
    var sHost = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    var BlogURL = decodeURIComponent(getQueryStringParameter("BlogURL"));
    var PostLimit = decodeURIComponent(getQueryStringParameter("PostLimit"));
    var BackgroundColor = decodeURIComponent(getQueryStringParameter("BackgroundColor"));
    var BlogTitle = BlogURL;
    if (BlogURL[BlogTitle.trim().length - 1] == "/") {
        BlogTitle = BlogURL.substring(0, BlogTitle.length - 1);
    }
    if (BlogTitle.indexOf("/")>-1) {
        var x = "/" + BlogTitle.split(/[/ ]+/).pop();
        if (x.indexOf(".") > -1) {
            BlogTitle = BlogTitle.substring(0, BlogTitle.lastIndexOf("/"));
        }
    }
    if (BlogTitle.indexOf("/sites/") > -1) {
        BlogTitle = BlogTitle.substring(BlogTitle.lastIndexOf("/sites/"), BlogTitle.length);
    }
    if (BlogTitle.length > 0 && BlogTitle != "undefined") {
        angular.module('blogPart', ['ngSanitize'])
          .controller('homeCtrl', ['$scope', function ($scope, $timeout) {
              $scope.BackgroundColor = BackgroundColor;
              $scope.PostLimit = PostLimit;
              console.log(PostLimit);

              jQuery.ajax({
                  url: BlogTitle + "/_api/web/lists/getbyTitle('Posts')/items?" +
                      "$select=ID,Title,Body,Author/Id,Author/Title,NumComments/Id,LikesCount,PublishedDate&$orderby=PublishedDate desc" +
                      "&$expand=Author,NumComments",
                  type: "GET",
                  headers: {
                      "accept": "application/json;odata=verbose",
                  },
                  success: function (data, status, jqXHR) {
                      //fill model
                      var postResults = data.d.results;
                      var items = [];
                      var today = new Date();
                      var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                      for (var i = 0; i < postResults.length; i++) {
                          var dt = new Date(postResults[i].PublishedDate);
                          var publishedTime = new Date();
                          if (dt.getDate() == today.getDate()) {
                              publishedTime = "Today " + (dt.getHours() + ":" + dt.getMinutes().toString());
                          } else {
                              publishedTime = (monthNames[dt.getMonth()] + " " + dt.getDate() + ", " + dt.getFullYear());
                          }
                          var authorName = postResults[i].Author.Title;
                          if (authorName.indexOf(",") > -1) {
                              var authorNameArr = authorName.split(",");
                              authorName = authorNameArr[1].trim() + " " + authorNameArr[0].trim().substring(0, authorNameArr[0].length);
                          }
                          var likes = postResults[i].LikesCount;
                          if (likes == null) {
                              likes = 0;
                          }
                          var item = {
                              id: postResults[i].ID,
                              title: postResults[i].Title,
                              body: postResults[i].Body,
                              author: authorName,
                              numComments: postResults[i].NumComments.Id,
                              published: publishedTime,
                              commentsUrl: BlogURL + "/Lists/Posts/Post.aspx?ID=" + postResults[i].ID + "#comments",
                              userUrl: sHost + "/_layouts/15/userdisp.aspx?ID=" + postResults[i].Author.Id,
                              likes: likes
                          };
                          items.push(item);
                          if (i == 3) {
                              $scope.$apply(function () {
                                  $scope.blogUrl = BlogURL;
                              });
                          }
                      }
                      //update ui
                      $scope.$apply(function () {
                          $scope.items = items;
                      });

                      $timeout(Communica.Part.init(), 3000);
                  },
                  error: function (jqXHR, status, message) {
                      $scope.$apply(function () {
                          $scope.error = "Error: " + message;
                      });
                  }
              });
              if ($scope.$last) {
                  console.log($('#blogPartContent').outerHeight());
              }
          }]);
    }
})(window.angular);

Communica.Part = {
    senderId: '',
    init: function () {
        var params = document.URL.split("?")[1].split("&");
        for (var i = 0; i < params.length; i = i + 1) {
            var param = params[i].split("=");
            if (param[0].toLowerCase() == "senderid")
                this.senderId = decodeURIComponent(param[1]);
        }
        this.adjustSize();
    },
    adjustSize: function () {
        var step = 30,
        newHeight,
        contentHeight = $('#blogPartContent').outerHeight(),
        resizeMessage = '<message senderId={Sender_ID}>resize({Width}, {Height})</message>';

        newHeight = (step - (contentHeight % step)) + contentHeight;

        resizeMessage = resizeMessage.replace("{Sender_ID}", this.senderId);
        resizeMessage = resizeMessage.replace("{Height}", newHeight);
        //resizeMessage = resizeMessage.replace("{Height}", $(document).outerHeight());
        resizeMessage = resizeMessage.replace("{Width}", "100%");

        window.parent.postMessage(resizeMessage, "*");
    }
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.