Friday, August 21, 2015

Adding Content Query Web Part to a master page

The situation: I'm trying to create a footer for my site which dynamically displays recent news articles, blog posts, and videos.

The problem: I'm having issues with both the Data View and adding my exported Content Query web part to my master page.  The CQWP is giving me an error message that the WebControls:ContentByQueryWebPart isn't cool, and the Data View is not filtering as I expect, and those stupid column headers are killing me.  I read somewhere that you shouldn't put CQWP on a master page, but I'm going to do it anyway.

The solution: After piecing together several articles (mostly about SharePoint 2010), I was able to make my content query solution work:

  1. Create a test page.  Add a Content Query web part.
  2. Configure it to show what you need.  Give it a useful name and hide the chrome.
  3. Export the web part.  Save it to the site collection web part gallery.
  4. Open the master page in SharePoint Designer.  (This is where I discovered that you have to hit Code View Tools > Parse HTML to be able to add any web part or code view to your page.  Every. Time.)
  5. Add these to the top of the master page:
    <%@Register Tagprefix="Publishing" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
    <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  6. Insert tab > Web Part > find your exported CQWP > click on it.
  7. SPD will insert your web part with this tag: <WebControls:ContentByQueryWebPart>.  This is what will create the error on your pages.  I added Publishing before WebControls in the opening & closing tags: <PublishingWebControls:ContentByQueryWebPart>.  All better.
  8. Save. Publish.

No comments:

Post a Comment