There have been a number of questions about one of my previous posts concerning filtering in the CQWP (content query webpart) in SharePoint 2010. In this follow up post, I will explain the entire case and process that I used to create a FAQ with out of the box content query webpart in SharePoint 2010.

The cliented wanted a list of frequently asked questions, which they could easily filter per category. Without using a custom solution, the best answer in MOSS 2007 would have been to create a page for each category, then place a CQWP to filter the applicable questions. This solution isn’t particularly satisfactory, as it is difficult to maintain.  The final solution was to use a managed metadata field to filter the query string, thanks to the new and improved CQWP in SharePoint 2010.

Step 0: Term store?

If you’re not too sure about taxonomies, please see my post on Understanding managed metadata. That will give you a brief introduction into what a taxonomy and tagging are.

One of the great things about SharePoint 2010 is the ability to work with a taxonomy – a central set of hierarchal terms which are reusable over multiple site collections. This structure is saved in the term store.  For more information on actually working with the term store and determining your taxonomy, please see Chris O’Brien’s Managed Metadata in SharePoint 2010.

Note that you can reach the term store via Central Administration or as an option on the site settings page of each site in your site collection.

Finding the term store

Step 1: Fill the term store

We need to save the list of FAQ Categories somewhere. My current rule of thumb is that whenever there is a site column that I would normally use a choice or lookup for, I now use the term store and make it a managed metadata column. So I made a new term set with a few terms:

You can place something like this wherever it works within your own taxonomy.

Step 2: Creating the content type

In  my site collection, I created a content type which inherits from the content type “Article Page”. I used the Article Page content type because I want each of my questions to be its own page – you could do this within a list meant for something completely different if you want to.

In this case, the site columns in Article Page map nicely to most of the site columns that I will need:

Question -> Title
Answer -> Page Content

Finally, I created a new site column of the type “Managed Metadata”,  called FAQ Category. In the column settings, I linked it to the FAQ Category section of the term store.

Step 3: Create the page layout

This is an optional step, but it’s necessary for the things that I want to show later on in this post. So I made a simple page page which shows the title and page contents site columns, linked to my FAQ content type, with the FAQ Category column in the hidden metadata section. I implemented two columns, one is used for the already mentioned columns, the other will be used later.

Remember that to work with SharePoint 2010, you need SharePoint Designer 2010. It is not backwards compatible with SharePoint 2007, nor can you use SharePoint Designer 2007 with SharePoint 2010. You can download it for free from the Microsoft site.

Step 4: Add some content

I created a few questions just to have something to play with in the rest of this post. You might want to do so as well, considering it’ll make it a lot easier to test what you’ve done.

Don’t forget to add the content type to your page library and all that jazz.

Step 5: Showing related questions

Here is where that extra column on the page layout comes in: we’re going to show the related questions so that visitors can click straight through to more interesting information.

On the page layout, add a CQWP.  The easiest way to configure it is to right-click it and then choose “Tag properties…” from the context menu that appears. Configure it as follows:

Show items from the following list

I’ve specifically chosen the page library that my FAQ pages are in. This doesn’t matter that much, it depends on your situation.

Choose content type

Specifically choose the content type you’re using – in my case, FAQ. This ensures that pages which use other content types (such as default.aspx) won’t turn up in the query.

Additional filters

SharePoint 2010 introduces two new filters in the CQWP which are very useful.  Note that there is a question mark next to the title – this has a good summary which always helps me out when I can’t quite remember the syntax.

PageFieldValue – allows you to use the current value of a field on the current page.
PageQueryString – allows you to grab the value of a query string in the URL.

We’ll be using PageFieldValue to get the value of FAQ Category for the current page. Using that, we can filter out other pages in the page library which have the same category.  The correct form is [PageFieldValue: FAQ Category].

When you view your page layout, it’s perfectly normal that the CQWP only shows dummy content. It will be visible when you check your pages via a browser – you can see the pages that have the same FAQ Category.

You can edit the CQWP further, for example to limit the number of results returned, change the sort order, etc.

Step 6: FAQ overview page

We need a good way to show the available questions, so the last step will be creating a page as an overview. I’m just going to use a blank webpart page for this one, though you can make it as pretty as you wish with a page layout.

Summary link webpart

The first necessary webpart is the Summary Links Webpart. I’m going to put this in the right column. For each FAQ Category, I will make a link. That link will point to the current page, with a query string which is linked to the category.

The “cat” is the query string variable. For each link, we’re saying “put the variable called ‘cat’ with the value ‘FAQ Category’” into the URL. This will be picked up on the page that the link goes to.

It is very important that the category that you put into the query string is exactly the same as the name of your category in the FAQ category managed metadata field.

Make a link in the webpart for each of your categories – each link needs to point to the current page.

CQWP

The next step is to place a CQWP in the left column. This will be picking up the correct FAQ pages for us.

The values for this CQWP are pretty much the same as for the CQWP when showing related information. Instead of filtering with the PageFieldValue, we’ll be filtering with the PageQueryString, to grab that variable out of the URL:

When you save/check the page in, the CQWP will be empty. Click on one of the links in your links webpart to see items from that category.

When you link to the page, make sure to include the query string with the category that you want to show by default, e.g. /default.aspx?cat=General info.

Conclusions

Managed metadata with the CQWP are powerful combination in SharePoint 2010. The examples shown in this blog post could not have been done this easily in SharePoint 2007, perhaps only with custom code.

Personally, I’m looking forward to having many more opportunities to use this functionality in the future!

Categorieën: Nieuws
Tags:
6 juli 2010 Fred

I am trying to use the [PageFieldValue: Field Name] you mentioned in Step 5 but web part properties wouldn’t accept the filter changes. Please illustrate the steps on how to use such token. I think I’m missing the step on adding a hidden field in Step 3 that will be used by the web part.

Note, I was able to use PageQueryString but I’d prefer to pass the title as filter parameter for CQWP.

Thanks!

14 december 2011 Basilios

What a great post. Exactly what i needed in building an FAQ library. I am currently using a list to generate every FAQ question. The CQWP is working just fine however i want the links to open up as a page or in a page within my page layout instead of taking me to the DispForm.aspx when the user clicks on the links. How to i achieve that?

Geef een reactie

Jouw e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *

*

De volgende HTML tags en attributen zijn toegestaan: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Categories

  • Tags

  • Blog Authors

    Amy
    anita
    Anneke
    Danny Burlage
    Dennis Vendel
    Freek Berson
    Gerard
    Iris
    Jasper Oosterveld
    Jean-Claude Chan
    Jorn
    Lab Chicks
    Luc Joziasse
    Maarten van Noort
    Maarten Wijsman
    Marlon
    Martijn Bellaard
    Natasja van Doorn
    Paul Pascha
    Peter Heuvelman
    Rick Slager
    Robert van Son
    Roel
    Roeland Jimenez
    SanderZ
    Sjoerd Schudde
    Stefan van der Wiele
    Tim Heuperman
    Wortell
  • Archief