Corrupted SharePoint Blog Post.aspx page and how to fix it

This is one possible solution which can also be applied to O365(possibly).

The solution is to re-activate two features related to Blogs site. These features should re-create the broken post.aspx page.

BlogContent $Resources:core,blogContentFeatureTitle; Web 0d1c50f7-0309-431c-adfb-b777d5473a65 $Resources:core,blogContentFeatureDesc;
BlogHomePage Blog Home Page Web e4639bb7-6e95-4e2f-b562-03b832dd4793 Creates the default.aspx page for the a Blog s

SharePoint 2013 Blog – Change the author of the post with a custom selected user

This is a sample JS to use with the posts webpart in the SharePoint blog(JSLink webpart property). Originally I wanted to the blog.xsl but I simply could not get it to world desirably in SharePoint 2013. Well it worked in a different manner that what it used to be in SharePoint 2010.

Here is the code with comments:

var userID = 0;
var globalListItemIDs = [];
var spjsLoaded = false;
var listName = “Viestit”;
var customUserFieldInternalName = “PostOwner”;

// Main function – Start point
(function () {

var overrideCtx = {};

overrideCtx.Templates = {};

// Register a template override for the author field
overrideCtx.Templates.Fields = {‘Author’:{‘View’:CBody}};


function CBody(ctx) {

// Load SP client context, ote async event
SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, sharePointReady);

// create a point of focus where to add the loaded information from the post item user field, Notice taht we are using the list item ID as an identifier where to put our user data
var ret = “<b><span class=’Blog_userTemplateContextData’ id=’userTemplateContextData” + ctx.CurrentItem.ID +”‘></span></b>”
var newListItemData = { id: ctx.CurrentItem.ID };


//var ret = ctx.CurrentItem.Body;

return ret;


function sharePointReady() {
if(spjsLoaded == true)
spjsLoaded = true;

clientContext = SP.ClientContext.get_current();
website = clientContext.get_web();

var oList = clientContext.get_web().get_lists().getByTitle(listName);

// Check if a specific post list item is specified, this would mean that the user is viewing a sigle post
var listItemID = getParameterByName(‘ID’);

// If no single post id is found then load all available posts and their custom users to be used instead of the author(TODO: Optimize for displayed posts only)
if(listItemID === null || listItemID === “”)
/*for (var iter = 0; iter < globalListItemIDs.length; iter++)
listItemID = globalListItemIDs[iter].id;
MakeNewDataCall(oList, clientContext, listItemID);
var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml(‘<Query><OrderBy><FieldRef Name=”Created” Ascending=”False” /></OrderBy></Query>’);
this.collListItem = oList.getItems(camlQuery);


clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
} else
// Only a single post is needed
MakeNewDataCall(oList, clientContext, listItemID);
var newListItemData = { id: listItemID };



function MakeNewDataCall(oList, clientContext, listItemID)
var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml(‘<Query><Where><Eq><FieldRef Name=”ID” /><Value Type=”Counter”>’ + listItemID + ‘</Value></Eq></Where><OrderBy><FieldRef Name=”Created” Ascending=”False” /></OrderBy></Query>’);
this.collListItem = oList.getItems(camlQuery);


clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded(sender, args) {

var listItemInfo = [];

var listItemEnumerator = collListItem.getEnumerator();

// Get the post data(single or many) and process it
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var listItemID = oListItem.get_id();

// Seek the SharePoint generated posts and seek if the current item is something we want to process
var userDataDiv = document.getElementById(“userTemplateContextData” + listItemID);
if(!(userDataDiv === null))
var author = oListItem.get_item(‘Author’);
// IF so then get the custom user information
var personOwner = oListItem.get_item(customUserFieldInternalName);
if(!(personOwner === null))
var name = personOwner.get_lookupValue();

// Put default data that is going to be used if a user image is not found, Notice that we define a user image location
userDataDiv.innerHTML = “<span class=’Blog_postUserData’ id=’postUserData” + personOwner.get_lookupId() +”‘>” + name + “</span>”;
var context = SP.ClientContext.get_current();
var web = context.get_web();
var userInfoList = web.get_siteUserInfoList();

// Make a call to the user profile information for this user to see if there is a user image available
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=”ID”/><Value Type=”Number”>’ +personOwner.get_lookupId()+ ‘</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>’);
this.listItems = userInfoList.getItems(camlQuery);
context.executeQueryAsync(Function.createDelegate(this, this.onProfileSuccessMethod), Function.createDelegate(this, this.onQueryFailed));

function onProfileSuccessMethod(sender, args) {
var item = listItems.itemAt(0);
var firstName = item.get_item(‘FirstName’);
var lastName = item.get_item(‘LastName’);
var userId = item.get_id();
// Get the location where the user image is to be inserted
var userDataDiv = document.getElementById(“postUserData” + userId);
if(!(userDataDiv === null))
// If there is an image then use it, if no image is provided do nothing and display the user full name instead.
var picture = item.get_item(‘Picture’);
if (picture!=null) {
userDataDiv.innerHTML = “<img class=’Blog_userDataImgClassStyle’ src='” + picture.get_url() +”‘ height=’42’><span class=’Blog_postUserDataName’ id =’postUserDataName’>” + firstName + ” ” + lastName + “</span>”;

function onQueryFailed(sender, args) {

alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());

function getParameterByName(name) {
name = name.replace(/[\[]/, “\\[“).replace(/[\]]/, “\\]”);
var regex = new RegExp(“[\\?&]” + name + “=([^&#]*)”),
results = regex.exec(;
return results === null ? “” : decodeURIComponent(results[1].replace(/\+/g, ” “));

New icon to CQWP – Content Query Webpart


So you may have wondered HOW to enable or add a new icon to a CQWP. Well aparently you can not do it through the user interface and you need to do some XSLT modifications. Here is what you need to do:

1. You need to download the following MS XSL file to datetime processing and add it into your XSLT file that displays your data:

The MS BLOG file

The XSL piece of code to add your XSL file, this will include the above downloaded file into your XSL file:

<xsl:import href=”/Style Library/XSL Style Sheets/date_templates.xsl”/>

2. Inside your XSL file that displays data(in the case of a CQWP lets say the item style XSL template) add the following lines:

<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateA” select=”@ArticleDate”/>
<xsl:with-param name=”paramDateB” select=”ddwrt:Today()”/>

<xsl:variable name=”article_date”>
<xsl:value-of select=”ddwrt:FormatDate(string(@ArticleStartDate), 1033,1 )”/>
<xsl:variable name=”today”>
<xsl:value-of select=”ddwrt:FormatDate(string(ddwrt:Today()), 1033, 1)”/>
<xsl:variable name=”date_diff”>
<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateB” select=”ddwrt:FormatDateTime(string(@PublishedDate),1033, ‘yyyy-MM-dd’)”/>
<xsl:with-param name=”paramDateA” select=”ddwrt:FormatDateTime(string(ddwrt:Today()),1033, ‘yyyy-MM-dd’)”/>

The above was meant for a CQWP that would lift the latest blogs inside a blog site. Notice the @PublishedDate parameter. This can be @ArticleDate or @ArticleStartDate etc. What you need to make the date difference calculations.

The date_diff XSL variable will hold the date time calculation between the blog post published date and the present date. Then you can use this value to determine when to show the New icon.

3. Add the logic to display the New icon. The below logic tells that if the items is less than 7 days old you need to display the New icon.

<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”New!” />

Sample in the XSL Blog title:

<div class=”blogListPostBlock”>
<!– Title –>
<a style=”color: #295AC6;”>
<xsl:attribute name=”href”>
<xsl:value-of select=”$SafeLinkUrl”/>
<xsl:value-of select=”$DisplayTitle” />
<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”Smiley face” />

Also please take into consideration that this is for the LCID language ID 1033 English  You need to make sure it fits your language if you wish to use a different language translation for New icon.