I'm using the content query webpart to query a blog list and it is working well for the most part, the issue i'm having has to do with the categories that the blog has been associated with when a blog has more than one category the PostCategory field contains data that looks like this:


Which contains both the id and the name of the category which I can use to build a link to the blog category filter page. When a given blog entry is associated with one category it the PostCategory field just renders out like this:


My question is how can I get the id of the category where there is only one? I know this has to be possible because SharePoint gets it with the stock blog template. I have combed through the blog.xsl file and have come up empty, any ideas on this one?

1 Answer 1


Did you define the Category field in the CommonViewFields property of the web part to pass as "Lookup" type? (a la: http://msdn.microsoft.com/en-us/library/ms497457.aspx)

Edit: snippet from my .webpart file as per the comments:

 <property name="CommonViewFields" type="string">PostCategory</property>
  • Yes I did. I'm getting 1;#Category1;#2;#Category2 when the blog entry has more than one associated category so it's pulling the right data. The problem is when there is only one there is no ID in the string.
    – James
    May 11, 2011 at 16:49
  • Odd - I've not seen this... and you're doing just a bog standard xsl:value-of yeah?
    – James Love
    May 11, 2011 at 16:59
  • Do you see an id in the string when there is just a single category association?
    – James
    May 11, 2011 at 17:12
  • Yep - though for me I had a teamsite at top of site collection level, created a blog underneath it, fired up the Publishing Infrastructure to get me the CQWP, added it, modded ItemStyle to spit out @PostCategory, exported a CQWP, wired it up to Posts list, added PostCategory to CommonViewFields, and it renders the number of the category as well as the name, even when only 1 is selected.
    – James Love
    May 11, 2011 at 17:46
  • Tried same thing you did, fresh team site with a fresh blog and the same result as before, could you update your post with what you have in your working exported webpart for => DataMappings, DataMappingViewFields, CommonViewFields?
    – James
    May 11, 2011 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.