Skip first 3 items in CQWP

I have 2 CQWP that make up the "Top Stories" section of our Intranet site. The first one is easy, it takes the 3 most recent stories and displays them on the page. Easy enough, that works fine. However... the second query is supposed to be the "archived" stories from prior months. the requirement is that they don't want to see the 3 current stories inside the archive until another replaces it. How do i tell the CQWP to skip the first 3 items in the web part. Let me know if you need further info.

Thanks in advance.

  • Edited by Mike Walsh FIN Tuesday, February 08, 2011 9:14 PM pressure removed.
February 8th, 2011 9:00pm

In most templates you have the CurPos variable which contains the number of the aggregation result. What you would need to do is to wrap the contents of your item template with <xsl:if test="$CurPos &lt; 3"> to skip the first three items.

Depending on the rest of your template you might also need to do some modifications in ContentQueryMain.xsl to make it render no wrapping markup for results that are being skipped.

Free Windows Admin Tool Kit Click here and download it now
February 9th, 2011 5:28am

Hi Waldek,

I was wondering whether you could provide me with a little more information on this? I am running into the same problem myself.

I have a single page with two web parts on it. One web part is called the "Featured Article", and the other is a "Older News" web part. I want the "Older News" article to show the second most recent article, and the "Featured Article" web part to show the most recently posted article. I've used the Content Query Web Part to display both.

Right now, both all querying just fine except that I want the "Older News" web part to skip displaying the first article, only showing the remaining 5 most recent articles. I'm struggling to see where I am able to do this. I tried your CurPos idea, putting this in the ItemStyle.xsl file but, when I call <xsl:value-of select="position()" /> I am always getting the number "1" return, for all of the rows.

Is there something I am doing wrong here?

March 16th, 2015 4:21pm

The trick is to call position() outside of ItemStyle.xsl. If you put it in ItemStyle.xsl you will always get 1 - just as you noticed, because the template is applied to one item. By calling position in ContentQueryMain.xsl, which iterates through all results, the position() counter will work as expected.

If you search for position() in ContentQueryMain.xsl you will see that it's already there but that it's not passed to ItemStyle.xsl. By passing it as a parameter to your templates you should be able to use it.

Free Windows Admin Tool Kit Click here and download it now
March 20th, 2015 1:51am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics