Adding a Like Button to Your Blog Post

Adding a Like Button to Your Blog Post

Posted by on Wednesday, June 3rd, 2015  

 

If you have a use for the blog site template, you've seen the OOTB experience provided by Microsoft. While useful, it has its short comings. I recently had the opportunity to take a look at customizing the view of a blog on O365 and I thought that this may help someone out there.

Let's take a look at customizing the view of the individual blog post page. We'll place a like button on the post.aspx page. This is what you would typically see when you select a post:

In order to do this you'll need administrator access to the site and you will need to be able to open SharePoint Designer for this as well.

When you connect to a site on O365 you will need to put in the full path including the "https" portion. Navigate to your blog site by using the left navigation area in SPD. Once you are there, on the left side select All Files - Lists - Posts. You should see this view:

Make sure you create a backup prior to any editing.

Right click and select edit in advance mode.

You'll be looking at the code of the aspx page. Look for this snippet of code, for me it started on line 68.

<View Name="{E8D26268-BD1F-4D2A-8660-12BB485BDA94}" Type="HTML" Hidden="TRUE" 
ReadOnly="TRUE" DisplayName="" Url="/sites/KCC1/Blog/Lists/Posts/Post.aspx" Level="1" 
BaseViewID="7" ContentTypeID="0x" ><Query><OrderBy><FieldRef Name="PublishedDate" Ascending="FALSE"/>
<FieldRef Name="ID" Ascending="FALSE"/></OrderBy><Where><Eq><FieldRef Name="ID"/><Value Type="">
<GetVar Scope="Request" Name="ID"/></Value></Eq></Where></Query><ViewFields><FieldRef Name="Title="Body"/>
<FieldRef Name="Author"/><FieldRef Name="PostedByWithDate"/><FieldRef Name="CategoryWithLink"/>
<FieldRef Name="Permalink"/><FieldRef Name="EmailPostLink"/><FieldRef Name="NumCommentsWithLink"/>
<FieldRef Name="PublishedDate"/><FieldRef Name="PostCategory"/><FieldRef Name="LikedBy" Explicit="TRUE"/>
</ViewFields><RowLimit Paged="TRUE">10</RowLimit><JSLink>sp.ui.blogs.js</JSLink><XslLink>blog.xsl</XslLink>
<Toolbar Type="None"/></View></XmlDefinition>
</WebPartPages:XsltListViewWebPart>

This is the template view for the post section of the page, here we will add an additional FieldRef link. The placement of the reference is very important as it determines where you will see the like button. Since we have Title, Body, Author, and PostedDate. We will add our reference after the PostedDate link. After you are finished you should see this.

<View Name="{E8D26268-BD1F-4D2A-8660-12BB485BDA94}" Type="HTML" Hidden="TRUE" 
ReadOnly="TRUE" DisplayName="" Url="/sites/KCC1/Blog/Lists/Posts/Post.aspx" Level="1" 
BaseViewID="7" ContentTypeID="0x" ><Query><OrderBy><FieldRef Name="PublishedDate" Ascending="FALSE"/>
<FieldRef Name="ID" Ascending="FALSE"/></OrderBy><Where><Eq><FieldRef Name="ID"/><Value Type="">
<GetVar Scope="Request" Name="ID"/></Value></Eq></Where></Query><ViewFields><FieldRef Name="Title"/><FieldRef Name="Body"/>
<FieldRef Name="Author"/><FieldRef Name="PostedByWithDate"/><FieldRef Name="LikesCount"/>
<FieldRef Name="LikedBy" Explicit="TRUE"/><FieldRef Name="CategoryWithLink"/><FieldRef Name="Permalink"/>
<FieldRef Name="EmailPostLink"/><FieldRef Name="NumCommentsWithLink"/><FieldRef Name="PublishedDate"/>
<FieldRef Name="PostCategory"/></ViewFields><RowLimit Paged="TRUE">10</RowLimit><JSLink>sp.ui.blogs.js</JSLink>
<XslLink>blog.xsl</XslLink><Toolbar Type="None"/></View></XmlDefinition>
</WebPartPages:XsltListViewWebPart>

 

The finished view should look like this.

 

Subscribe to RSS Feed

Sign Up for Newsletter

Leave a Reply