Content Query Web Parts.. the new god?

I’ve only worked with the CQWP a few times and have never really got under the bonnet, however just recently at a client they had a requirement that I couldn’t solve OOTB… Time to dive into the inner workings of the CQWP.. And boy am I glad i did.. this web part rocks!

There are many good blog posts on how to tailor the content being returned from this web part and how to style the output, so I’m not going to re-create those here. For those new to CQWP, take a look at Heather Solomons blog post on tailoring it to your design..

I used that post to deliver two versions of the CQWP on a page. The first showed only the latest story from the news site, with a top left picture and the body of the article page flowing around the image.

The next web part was a roll up of the next 4 stories containing the first 200 characters and a read more link… Now this is where I hit my problem. I could return the 4 most recent stories, but I already had the most recent on the page, so I didn’t want to show a summary of that story as well.

To get around this, we need to look further into the XSLT being used to display the results. In order to help you do this, I’d recommend using the technique shown on Frank Moss’ blog to show all the data being returned by your query.

When you examine the output of this, you’ll notice that we have several fields to work with. The one that I’m interested in is “__beginColumn” as this appears to only return a True for the first item.

Now i’m sure that at somepoint, another entry is going to pick up the True again to start a new column, but I’m only interested in the first four items, so I’m going to work with this and see if it falls over in the UAT environment..

In your custom XSLT that you’ve created for your CQWP, we need to wrap the output section for the summary part in an XSL:If statement. but to do this, we need to work with a variable.. So, in the variables section of your chosen style, add the following:-




This gives us the value of “columnStart” to play with.. So now we wrap the output section of the chosen style in the conditional..

     
     

Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.