Fixing the date archive page in a Sharepoint Online 2013 blog site

Categories, date archive pages not filtering posts?

It’s a common problem: the category and date archive pages  on a Sharepoint blog site stop working and users see all posts instead of a filtered view.  It’s easy enough to insert a new “blog tools” web part (which a well known bug breaks if you edit the category.aspx or date.aspx pages). If that doesn’t do it, there are several articles about how to fix the category page – like this one:

The fix involves restoring a CAML query that Sharepoint mysteriously strips out. The same approach applies to the date archive page  but the specific query is different and hasn’t received as much attention, so I thought it worthwhile spelling out what needs to be done.

Restoring the missing CAML query

In Sharepoint Designer, open your blog site and navigate to the date.aspx page in the posts list.

It’s always a good idea to make a quick copy of ANYTHING you edit in Sharepoint, before diving in. Then, edit it in advanced mode.

Do a search for “<Query><OrderBy><FieldRef Name=”PublishedDate” ” to locate the section of the posts list view web part that needs to be edited.

After the closing orderby tag  “</OrderBy>”, add the following CAML query:

<Where><And><And><Geq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime” IncludeTimeValue=”TRUE” StorageTZ=”TRUE”><GetVar Scope=”Request” Name=”StartDateTime”/></Value></Geq><Lt><FieldRef Name=”PublishedDate”/><Value Type=”DateTime” IncludeTimeValue=”TRUE” StorageTZ=”TRUE”><GetVar Scope=”Request” Name=”EndDateTime”/></Value></Lt></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where>

It should look like this:

Click to enlarge »

Since this is generic code with no guid’s, and doesn’t appear to have changed much over the years, it’s “safe” to use and  should work in any blog site in any version of SP.

Now, save the page, open it in the browser, restore the “blog tools” web part which will inevitably be broken and check that your filtering is working again.

The straw that broke the CAML’s back

WHY the CAML query gets stripped out remains a mystery and is another example of the questionable development standards in Sharepoint, the platform’s fragility and Msft’s lack of focus on the user experience. But at least now there’s a quick and easy fix.



Add scripts/iframes to Sharepoint 2013 blog posts.

If you add code for an iframe or a script to a Sharepoint blog post, you’ll be greeted with an annoying alert that warns you that: “some of your html may have been modified”. In effect, filters in the text editor strip out your code as a result of one of Microsoft’s odder design decisions: to allow iframe and script codes in a page but strip them out from the rich text “body” field in their blog post template. This inconsistency is annoying andnot getting any attention from Microsoft, so we need to workaround it.One option to get around this odd restriction is to add another field to the post list view web part that will dodge the rich text field filters, and render iframes and scripts right below the body field. This article will show you how to do that in 4 steps:

1/ Add an html field to the post list
2/ Rig it so it renders as html not text
3/ Add the field to the list’s views
4/ Add a simple script via a jslink file so it shows up in the post.

Add an html field to the post list
Navigate to your blog post list’s settings and add a single line text column called”html” to the list.

Rig it so it renders as html not text
Add a calculated column with this formula:=html.
Name the field”Calc” – if you use a different name make sure you update the field name in the jslink file referenced below.
Important:SELECT “NUMBER” AS THE OUTPUT. This little trick ensures the code you enter in the html field will render as code and not plain text. Keep in mind the character limit of a single line text field is 255, so your code will have to be below that!

Add the field to the list’s views
Adding a field to the post list view and then updating the view on the post.aspx page will break the connections and scripts that make the blog work. So you will have to open the post.aspx page in Sharepoint Designer, click into the appropriate list view web part and use the”add fields” tool in the ribbon.

Because of a bug and Msft’s lack of quality control, the list view tools may not be visible, in which case use this trick:
Right click the list view web part.
Click”tag properties” which will open the properties dialog and then OK.

Now the tools should show up, and you can add the”Calc” field to the list view web part. You will need to repeat this for the other blog pages if you want your html to show on them: date.aspx, default.aspx, category.aspx.

NOTE: If your html field returns “undefined”, go back to post.aspx in SPD and make sure the field ref name of your field (“html”) is included in the query of the list view web part.

After editing these pages, you’ll notice the”blog tools” web part now displays an error and the page may not look right. This is another bug in SP that you can easily repair by adding the blog tools web part again and deleting the original.

Add a simple script via a jslink file so it shows up in the post.
If you’re not familiar with jslink, you can download the file below and upload it to a root library, such as site assets.

To connect it to your list view web parts, open up the web part properties and under”Miscellaneous>jslink” add the path to the file formatted with the appropriate site token. For example, for, use ~sitecollection/siteassets/blog-html.js. The token MUST be used for jslink to work.

Download jslink file here

Add your code
To test, edit a post and add a simple iframe code to the new”html” field. As mentioned, you cannot exceed 255 characters. I wrapped the html field in a span with a class of “post-html”, so you can adjust the styling as needed.


Visit my forum » if you have any questions. For development work, you can contact me here ». And if you think this would be useful to others, feel free to share it by clicking one of the share buttons up top!

How To Restore An Office 365 Sharepoint Online 2013 Public Site Blog Without Using Code

f0101471Based on the number of “broken blog” threads in the O365 forum, it seems the public site blog provided in O365 is pretty fragile. It’s also not immediately obvious how to restore it. If you deleted any of the blog pages and are able to restore them from a recycle bin, it’s likely you still won’t get the full blog functionality back.Here’s an example of a blog rebuilt from scratch:

And here’s the quick code-free way to get your blog back up and running.
The Easy Part
Create a new public site page and select either the right or left sidebar page layout.
In edit mode, click insert and from the App Part list insert a “Posts” list into the main page area.
Click the web part and select “web part properties” from the ribbon.
Important! In the properties dialog box, change the “view” to “summary view”
Save the page
Click the sidebar zone, insert » web part » Blog » Blog Archives
Below that, insert the Blog Tools web part
Save the page.
Now you should have most of the blog functioning on the page. What’s missing is the categories web part which is a wee bit trickier to get working.

The Hard Part – Categories.

As far as I can tell, the categories web part works by sending a filter to the posts list so only posts in the selected category are displayed. To make the category title a link that triggers the filter requires some complex recoding of the web part and I assume that’s what the mystery script Microsoft may provide you does.If you don’t want to wait for that script and don’t know how to recode a web part,you can recreate the effect without code:

Go to site contents » categories » list settings » views and make sure you have a view which contains a plain text title field (ie iwthout a hyperlink).
Open your blog page in edit mode and from the App Parts, insert a categories web part in the sidebar.
Edit the web part and select the view that has the plain text title field.
Save the page.
In edit mode, open the web part context menu (from the little down arrow at top right)
Click Connections » Send Row Of Data To and choose “Posts”.


In the dialog box that opens, confirm that you want to send a row of data and then select from the options in the “provider” and “consumer” field names. Translating the Microsoftspeak, the “provider field” is the field you want to use for the filter and the “consumer field” is the matching field on the receiving end. In this case, the category list “Title” field corresponds to the “Category” field in the posts list, and when the filter is applied onlyposts with that category name in its category field will show,


Click Finish and save the page.
Your categories web part should now include a small filter icon that will filter the posts displayed based on the category chosen. Not as neat as a linked category title, but it works and you don’t need to delve into the code.

The Last Part

Your blog should now be fully functional and you can start using it. If you find you get web part errors on the single post page or you have any other questions, feel free to post a questionin my forum or contact me here.
I hope this was useful!

Adding video to a Sharepoint Online blog post (SharePoint 2010)

wmpWhen you create a new blog site in SPO, the default blog post promises it will: “….help you share information related to a particular subject area in the form of text, images, links, and other media such as video”. Unfortunately, Sharepoint strips out any embed tags like iframe or object from any list, so video can’t be directly added to a post – which is actually a list item in a standard list.This article will show you how to workaround that restriction and insert any embedded content into any list – in 3 easy steps.

Add an empty div to a post (or rich text field in any list).
Insert a content editor web part linked to a file
Create a file with a little javascript that injects your embed code into the empty div in the list
By locating the embed code outside the list, the “illegal” embed tags are rendered after the list and aren’t detected by the list filters. Javascript insertsyour embedded content inside the blog post wherever you inserted the empty div. And, yes, you’ll finally be able to add video content – beloved by search engines everywhere – to your blog. (I’m using a blog as an example here, but this can be adapted to insert any kind of coding into a rich text field in any type of list).
What you’ll end up with is a really easy way to manage embedded content. By simply adding or adjusting the embed code in one “central” text file, you can add a new video, change dimensions, change videos, insert a powerpoint slideshow etc. And since this technique only uses standard web parts and javascript, it should work the same no matter which version of Sharepoint you’re using – 2010 or 2013.

Here’s how:
Since we’re talking about adding a video to a Sharepoint list, here’s an example – an embedded video that will show you how to do just that. Text instructions and the code snippets needed come after the video!


1/ Insert an empty div
Open the post for editing and click the “edit html source” button. Add an empty div where you want the video to appear.
Give it an id you will use later in the javascript: in this example –

div id=”test”></div


2/ Add a content editor web part
All the posts use the post.aspx page so to open it for editing enter //Lists/Posts/Post.aspx?ToolPaneView=2&PageView=shared
Click “add a web part”, select a content editor web part and then click “edit web part”
In the properties box, enter /Documents/test.txt in the “content link” pane
The code MUST be rendered after the empty div so select the right zone under “layout” to make sure it is.
Select “None” for the chrome type so a web part title doesn’t show in your blog.
Save the web part and the page

3/ The code
You can either create a text file with the code below and upload it to the Documents library, or even easier create it right in Sharepoint Designer. Just make sure the id (in this example: “test”) corresponds to the id of the div you added to the list in the first step.
Open the site in SPD – navigate to the Documents library – click the new file tool and select text file – change the file name* – paste in the code below.
*The only requirement for the file name is that its url correspond to what you entered in the content editor.

Video inserted in post–>
script type=”text/javascript”>
vartest=document.getElementById(“test”);if(document.getElementById(“test”)){document.getElementById(“test”).innerHTML=’YOUR EMBED CODE GOES HERE-YOU CAN PASTE IT FROM YOU TUBE OR OTHER HOST’} /script>

Once you save the file, the content editor will run the code and bypass Sharepoint’s restriction on embedded content.

Multiple videos on a page
Since all posts use the posts.aspx page and the text file is already being referenced, you can add more instances of the inner html javascript to the text file. Each instance must have a unique div id which must be referenced in the file. In other words, you can add an empty div with an id of “test2” to the same or another post, and repeat the javascript in your file using “test2” in place of “test”.
One more trick: once you’ve inserted the content editor web part on one page, you can save it in your web part gallery and make it available for use on other sites or pages. To do that, select the web part in Sharepoint Designer. Click “Web Part Tools – Format” in the ribbon. Click “To Site Gallery” under the “Save Web Part” section. To add it to another page or site, select where you want it in design view (in SPD), open the web part tool and insert it.


Create a public blog site in Office 365 Sharepoint 2010

Applies to: Sharepoint 2010! It’s easy enough to add a blog sub site to your Office 365 public site. First, open your Team Site and go to site actions / site settings / site collection admin / go to top level site settings / site admin / sites and workspaces.
Or you can append _layouts/mngsubwebs.aspx to your domain which will take you to the same place.


Next, click create and give your blog site a name and an address. Under “Template selection” choose the “blog” template from the “collaboration” tab and click “create” at the bottom.


This will add a blog subsite to your public site. Now when you’re logged in, you’ll see a “blog tools” navigation area on the right which is how you manage your blog. Easy, huh? But the problem is even though the blog is a sub site of the public site, and should inherit it’s anonymous access setting, there’s no way to grant anon access to the associated comments/categories lists. They will trigger a log in because of the way 365 is configured, so it’s not of much use.
Fortunately, a 365 user named Martin Hatch has come up with a very user friendly solution to allow anonymous access to ALL areas of your blog. This has been tested to work in P and E type accounts. (Just like OLSB, it’s the user community that’s going to make O365 a more useful product!)
Click here for Mr Hatch’s article which outlines what you need to do. But since OLSB refugees may not be familiar with the steps involved I’ll give a bit more detail.

First download the .wsp file from the article.
Then open your Team Site and go to site actions / site settings / site collection admin / go to top level site settings / galleries / solutions and click the “solutions” tab. (You can also append _catalogs/solutions/Forms/AllItems.aspx to your public site domain to get there faster).
In the ribbon, click “upload solution” and select the wsp file you downloaded.


Check the box next to “HatchSolutions.Office365.BlogPermissions” and click “Activate” in the ribbon.
Now go back to “website” (append /Pages/Forms/AllItems.aspx to your website domain if it’s easier)
Open the blog sub site you created. Click “site actions” and “Edit page”.
Under the “Page tools” tab, click “insert”.


Click “More web parts” and you’ll see all the web parts available to this site. You should see “Hatch solutions” in the left nav-click it and select the “Set anon blog permissions” icon.


Click “Add” on the right and you’re done! The code that runs in the solution has done its job and changed the permission settings for your blog site, so you can now delete the web part if you like. Take a look at Martin’s article for more information.
And THIS blog is what your blog will look like. It ain’t the best looking blog in the world, but it works.
If you want to embed the blog on your public site, you can do so with the provided rss feed url which will look like this: 365 blog on a public site.
We cover that in another article:An Office 365 Blog served up using an rss feed.

An Office 365 Blog served up using an rss feed

How do you get a 365 blog published on your public site?MSFT makes it more difficult than it should be, but here’s one way.
Create a blog sub site under the public site collection in 365. Use the rss feed to embed the blog on your public site.
You could see the original blog the feed is from here but the link tool is broken in Sharepoint.
See the blog feed on a public site page here.
UPDATE:This worked for a while – displaying actual posts on the public site via rss – but now it just shows a link to the blog, so it looks like MSFT has closed off yet another useful feature of O365.