This blog is also featured on NothingButSharePoint.com
Note: This post was updated Dec. 5 to correct a few errors in the code markup.
This is a solution to create a jQuery slider (carousel) in Sharepoint 2010. It is based on an image library, and uses the tinycarousel jQuery plugin. You should end up with something like this:

By the way, subscribe to my RSS feed to get all this goodness in your feed reader!
Skip to the section you need:
1. Column Settings
2. Page Layout
3. itemstyle.xsl
4. the CQWP
5. jQuery + CSS
Column Settings
Audience targeting: ON (so only some images can be seen by some people)
Extra Columns:
- Link to Page (single line of text)
for the destination url the image should link to - Ad Category (Choice)
this is so we can style the icon next to the caption based on the image category - Start Date (Date & Time)
when the image should start displaying - End Date (Date & Time)
when the image should stop displaying - Target Audiences (Audience Targeting)
automatic column added when audience targeting is enabled

Page Layout
Create a page layout called “Slider” (or whatever you want).
Note:It’s necessary to use a custom page layout for this slider because we need to wrap the Content Query Webpart and call our custom jQuery.
Layout your page like this:
<div id="slider-code">
<a class="buttons prev" href="#"></a>
<div class="viewport">
//insert CQWP here
</div>
<a class="buttons next" href="#"></a>
</div>
Create a new style in itemstyle.xsl
This is super simple. Create a new style named “adverts” (or whatever).
<xsl:template name="Adverts2" match="Row[@Style='Adverts2']" mode="itemstyle">
Then we’ll want to pull in the image, and wrap it in a link that goes to the URL we gave it.
<a href="{@LinktoPage}">
<img src="{@FileRef}"/>
</a>
Next, create a variable called “category”. We’ll pass this into the field that displays the icon based on the category of the picture (in my case, news, announcement, or calendar item).
<xsl:variable name="category">
<xsl:value-of select="@AdCategory"/>
</xsl:variable
Next we’ll put the caption below the image, calling the variable we just created.
<div class="caption">
<img src="/Style Library/images/{$category}.jpg"/>
<xsl:value-of select="@Title"/>
<a href="{@LinktoPage}">Read More</a></div>
Make sure to close your template.
</xsl:template>
See my final image below if it helps to put it all together:

The Content Query WebPart
The first set of settings for the CQWP are as follows:
Content Type
Show items of the “Document Content Types” group, and show items that have “picture” as the content type.
Audience Targeting
Make sure to enable audience filtering and include items that are not targeted. See the image below.

Additional Filter
Set the Start Date to “less than or equal to” [Today]
Set the End Date to “greater than or equal to” [Today]
This will show only items that are “active” today. See the image below.

Styles & Fields to Display
Set the item style to “adverts” (the xsl style we just created).
Set the fields according to the columns “Title”, “Ad Category”, and “Link to Page”. You can leave “FileRef” blank. See the image below.

jQuery & CSS
Last but definitely not least, let’s put the jQuery scripts in that make everything run. And then style everything with CSS.
In your page layout, add an ASP:Content placeholder like this (don’t forget to close it)
<asp:Content ContentPlaceholderID="PlaceHolderAdditionalPageHead" runat="server">
Within that placeholder, put the following script:
<script src="/Style Library/scripts/jquery.tinycarousel.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#slider-code").tinycarousel({animate:true, duration:900, interval:true, intervaltime:5000});
});
</script>
This assumes you have the standard jquery script already loaded in. As you can see, the settings for tinycarousel are very simple once you have the plugin linked in. Just make sure the id of “slider-code” indeed matches the id of the div you have wrapped your CQWP in.
the CSS
You can copy the css from below, or just click here to download my CSS file.
/**** slider Carousel *****/
#slider-code {
height: 325px;
overflow: hidden;
position: relative;
width: 540px;
margin-bottom:10px;
}
#slider-code .viewport {
float: left;
width: 540px;
height: 325px;
overflow: hidden;
position: relative;
display: block;
}
#slider-code .buttons {
display: block;
width: 50px;
height: 50px;
position: absolute;
left: 0;
top: 0;
z-index: 50;
text-indent: -9999px;
color:#fff;
border:1px solid #ccc;
}
#slider-code .next {
left: auto;
right: 0;
background: #fff url(images/rightarrow.jpg) no-repeat center center;
}
#slider-code .prev {
background: #fff url(images/leftarrow.jpg) no-repeat center center;
}
#slider-code .disable { visibility: hidden; }
#slider-code .dfwp-list { list-style: none; position: absolute; padding: 0; margin: 0; left: 0; top: 0; }
#slider-code .dfwp-list li.dfwp-item { float: left; margin: 0px; padding: 0px; height: 335px; border: 0px solid #dcdcdc; width: 540px;position:relative;overflow:hidden;}
#slider-code .dfwp-list li.dfwp-item .caption {
display:block;
color:#666;
float:left;
font-weight:normal;
margin-top:10px;
width:540px;
margin-right:0px;
height:50px;
}
#slider-code .dfwp-list li.dfwp-item .caption a {
color:#005baa;
}
#slider-code .dfwp-list li.dfwp-item .caption img {
width:30px;
height:30px;
margin-right:10px;
float:left;
background:#fff;
}
tweet
Hello, This looks exactly what I’m trying to do: A slider with the CQWP as the source. I’m trying to follow your article, but I’m stuck at “Create a Page Layout”. What should the page layout be based on? I have tried a Wiki page and an Article page. where does the go? Don’t I need a content field, so I can add a CQWP? If I add a content field and save the new layout, then create a page from the new layout, I can add a CQWP, but I cannot edit the page in SP Designer after that.
Would you mind explaining the exact steps in a bit more detail, please? I’m just starting with SharePoint Designer and I’m a bit lost, but I’d really like to get this going. I have the ItemStyles.xsl and all the rest set up. Just the Page Layout How-to is missing.
I’d be very grateful for a reply.
cheers, teylyn
Hi Teylyn,
Thanks for the question. Let me clarify a bit. Everything (the entire tutorial) is happening in the page layout. Nothing is actually done in the browser. This page layout can be used to make other pages, but the slideshow you make will be essentially “embedded” in the page.
The page layout can be based on anything…doesn’t really matter. But I have mine based on a standard page content type that has a title and a body. So what I do is (in Sharepoint Designer) go within the PlaceHolderMain content placeholder and create the “slider-code” div, with the “viewport” div, and then in Sharepoint Designer I go to Insert > Web Part > Content Query. So you can see, the CQWP is actually embedded in the page layout. So, for example, I used this page layout only once for my home page. I put a few other webpart zones in the page layout, and any other fields so I can put more specific stuff browser-side. But as far as the slider is concerned, it is put in the page layout, not in the page. Hope this makes sense! Let me know if I can clarify further.
Ben
something got cut off above. Where it says
where does the go?
I meant to say: where does the div id=”slider-code” go exactly?
Sigh ~ It does not work….
Can I help?
lemme say … great work!
I am trying to use this for my document library. I got all the pieces in place… see the right and left arrows with the image and read more link to the document. But clicking on the arrows does not move to the next document. Which part of the code does that? the jquery file should do it?
please advise
It would be useful to have this tutorial simplified a bit if we just wanted to ‘manually’ insert a TinyCarousel slider into a page without being linked to a CQWP. I think that would help understanding of how to embed widgets and the like in standard aspx pages.
For example my master page references jQuery library 1.4.2 – as we use it around the site – but I can’t get the TinyCarousel to work at all. Frustrating!
Hey Dan. So where are the source files for the slider you want to embed in a page? I’d be interested in digging into it a bit more, and as you said, maybe posting a more scalable version of this that you can take to standard aspx pages.
Ben
I am trying to use this, but the problem I am having is that the query seems to be coming back empty.
I have a div.cbq-layout-main that has nothing in it. Nothing seems to be placed from the xsl template that I entered.
Can you help out?
Yeah, happy to help out. But can you send me any more info (xsl code, setup details, etc.)?
Thanks but I went with another solution here: http://blogs.pointbridge.com/Blogs/broweleit_seth/Pages/Post.aspx?_ID=15#EntryTabs It has less features, like anchors on the images, but it still pulls most recent content via javascript. Not the most degradable solution but it works for now.
Thanks!
Thanks but i’m a noob in sharepoint plz can we do that in a video it will be much easier for us
Thanks for this nice explanation.
But you have forget to say to edit JS file.
because in JS/Javascript file jquery.tinycarousel.min.js it standing .overview. this class doesn’t exit in HTML file. you must change .overview to .dfwp-list so it can work together with list item in SP.
And than you will see results.
sorry for my english if you need files to download ask.
Hmmm. I don’t remember editing the source of the jquery plugin. The script should actually let you choose the div you are applying the script to, right? I’ll have another look and make sure.
hi ,
i was made every thing but it does not work , please if you can show that into video it will become more easy
give me some time I’ll make a guide for you with all files that you can download to get work.
I’M using this slider for publishing website for RAI organisation I’ll show you also live demo with different styles.
Thanks to this guide i have a new slider to my collection.
(video rec I don’t using that.)
Hi, Brilliant Post. I am following your post to create a visual webpart for my Sharepoint 2010 Online environment. I am creating a slideshow webpart, where images are selected from a picture library and displayed in a slideshow.
I have custom properties in my web part to allow the user to select 1. to reduce the size of the images; 2. web part background colour; 3. Types of Transition; 4. Length of display; 5. Image Text and Description and where to put this; 6. Size of the web part (to reduce whitespace around image).
I do know that I have to use J Query, XSLT and CSS to style and rotate the images, but I don’t know how to get my editor web part properties from the web part to my XSLT and Javascript. I need the values entered by the user to be used to set the values in the javascrispt to control how the slideshow is executed. Then I have to package all this into a Sandboxed solution for deployment. Can you help? thanks in advance.
Hi Tenille,
Sounds fun! I’m not a developer in the traditional sense, I really do more of this front-end stuff dealing with not much deeper than the browser. I assume you’re doing this stuff in Visual Studio, right?
I do know that for custom webparts, you can attach your own XSL, CSS, jQuery, etc. But I assume if you are putting controls in your webpart, then somehow you have to store those variables somewhere. I’m not entirely sure where those would go though, bummer.
Sorry, wish I could be more help. I’d be really interested to see how you did it if you manage to accomplish it though. It’s something I’d love to be able to do.