As I've finally deployed my blog to the world, I stumbled across an interesting quirk associated with the Content Query Web Part (CQWP). The problem, which has been described by other blogs, is that the links to items presented in the CQWP are not anonymous-friendly. The titles are shown as expected, but clicking a link result in a request that the user provides credentials. Without proper credtials, users are directed to a "403" error.
Rather than linking to the item directly, all links go through CopyUtil.aspx. After some research, I've learned that this page, without customization, does not support anonymous access.
I decided to follow some instructions from
Heather Solomon's Blog on customizing Item Styles for the CQWP and create my own Item Style for Blog Posts.
For this example I am going to present a list of Blog Posts -- which you can see on most (if not all) of my
Blog Pages.
1. Configure the CQWP with Default Settings
To begin, follow any number of instruction sets for using the CQWP. If you don't know how to use the CQWP, try starting with some help from
Microsoft.
Once I was convinced the query was right (using the default style), I saved my changes and moved over to SharePoint Designer (SPD).
2. Create a Custom Item Style
Within SPD, navigate to the XML Style Sheets folder within the Style Library. Notice that I'm at the parent site level, not the sub-site.
Open the
ItemStyle.xml file (you may have to check it out).

Looking in this file, and this is important if you're not familiar with working with it, you'll see that there are a number of XML entries starting with <XML:template... This indicates a style template that you can customize, or copy and change for your own liking. That's what we're going to do.
Copy the XML.template section for default (see image) and paste it down at the bottom of the file (but before </xsl:stylesheet>).
Now change the template name and match="Row... entries:
<xsl:template name="ListofBlogPosts" match="Row[@Style='ListofBlogPosts']" mode="itemstyle">
Next, let's replace the code that displays the hyperlink to the blog item. To do this, I commented out the code provided by Microsoft and added my own:
Here's the code if you'd like to copy & paste
<xsl:text disable-output-escaping="yes"><![CDATA[<a href="Lists/Posts/Post.aspx?ID=]]></xsl:text>
<xsl:value-of select="@ID"/>
<xsl:text disable-output-escaping="yes"><![CDATA[">]]></xsl:text>
<xsl:value-of select="$DisplayTitle"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</a>]]></xsl:text>
Save the file (you may have to check it in and publish it).
3. Update the CQWP to use this new Style
Return to your browser and Modify the Shared Web Part for your CQWP. Expand the Presentation section. Under Styles, and select the new Item Style (ListofBlogPosts, for my example).
Click the OK button and confirm that your new style displays the correct blog items and the hyperlink links directly to the post.
I hope this helps.
- Mike