Building Slideshows with Navigation Based on Views

Submitted by Ki Kim on Tue, 01/03/2012 - 9:57am
Ki Kim's picture

Slideshow is a popular feature on the front page of many web sites. Drupal makes it quite easy to build one. Here are the steps to build a Views-based slideshow in Drupal 7.

The ingredients you need are Drupal 7 core, Views module, and Views slideshow module. If you are testing out fresh, Chaos tools module will be required for Views.

Create a new view

Start by creating a new view. I gave it a name 'slideshow'. Uncheck the default checkbox for 'Create a page', check 'Create a block', and proceed with the [Continue & edit] button.

Add fields that you want to show in the slideshow. I added image, title, author, comment count, and Global: View result counter (explanation coming for the last field).

Note that in Views 3, author name is not provided by default (only user id is). You need to add relationship 'Content: Author' in the 'Advanced' section, which is initially collapsed.

The filter criteria of my choice is shown as follows. I've also selected the format to be Slideshow.

Enable the block

After saving the new view, a new block 'View:slideshow' is available on the Block admin page (/admin/structure/block). Enable the block in one of the regions on your front page and it will look something like this.

There are image, title, and author followed by the comment count (2) and its position (3) in the slideshow; i.e. it is the third slide in the pool. This is the field 'Global: View result counter' when you created the view.

Style navigation buttons

Now let's style the navigation of the slideshow that allows users to jump and pause to any slide. First, hide the currently showing the view result counter by checking 'Exclude from display'.

In the Format section, click on settings (Choose Format as 'Slideshow' if you have not already done so in the previous step). Go to 'Bottom Widget' section and check 'Pager' and then check 'Global: View result counter'. This is the real reason that we have added the field for the result counter.

After saving the view, the block now looks like this. Note the last 4 numbers.

Reviewing the code for the counter numbers (using a developer tool such as Firebug) shows that the css class names are changing in real time when the slide changes. Using this information, we can insert this style in current theme's css file,

.view-slideshow .views-content-counter {
  background-color: #9FC4DC;
  border-radius: 6px 6px 6px 6px;
  float: left;
  height: 12px;
  width: 12px;
  margin-right: 5px;
  text-indent: -9999px;
  cursor: pointer;
}

.view-slideshow .active .views-content-counter {
  background-color: #2874A2;
}

to achieve graphical interactive navigation. The elements were already equipped to be interactive by Views and Slideshow modules. With further styling the slideshow can look like this.

The navigation button style was achieved using css styles without images. The circle buttons will look square in a browser that does not support rounded border corners such as Internet Explorer. If you need a more consistent look, you can use images instead.

Chris Loos helped with the theming.

13 comments

by eigentor (not verified) on Tue, 01/03/2012 - 3:12pm

A big thumbs up for global result counter.
I tried a lot of other ways and did not succeed in doing what you describe here. All the time I thought "Damn, Views is sure able to do it, why can't i find it".

Turns out my colleague Johannes had the solution.
Also big thumbs up for Merlinofchaos, Daniel Wehner and all the Views contributors.

by lyle@4fs (not verified) on Wed, 02/01/2012 - 3:06am

Hi

How do you link the numbers to the images in the slideshow? been having this problem for a few days

by Neil (not verified) on Thu, 02/16/2012 - 5:02am

Thank you very much for this. I knew how to make a slideshow, but I just could not work out how to do the navigation buttons. Your tutorial is exactly what I've been looking for, and you've saved me hours of headaches.

by Periku (not verified) on Wed, 03/28/2012 - 6:25am

thanks. save me hours.

by javiercito53 (not verified) on Thu, 03/29/2012 - 2:02pm

I couldn't find how to show the number of each slide, Thanks!

by Ashton M (not verified) on Mon, 04/16/2012 - 7:28am

I tried a lot of other ways and did not succeed in doing what you describe here. Turns out my colleague Jamie had the solution.
Also big thumbs up for Merlinofchaos, Daniel Wehner and all the Views contributors.
Ashton from <a href="http://demotivators.edublogs.org/" title="demotivational posters">demotivational posters</a>

I have gallery formatter - colorbox nodes. I would like to make a views slideshow block at bottom panel which will display one image or all images from each node (one by one) and linked (on click image open the original page). Also would like to do the same with thumbnails pictures of video pages link the same way. Is it possible in views slide show 3? drupal 7.12

by Mikkel Brynildsen (not verified) on Tue, 05/01/2012 - 1:16pm

Hi.

I had problems getting the pager to actually change the images, but after removing the Devel module it works, the paging numbers are not printed as links, but when clicked they now change the slider.

by steve (not verified) on Thu, 05/10/2012 - 7:31am

Thank you for this little slide show module

by handinherpocket (not verified) on Sat, 07/07/2012 - 12:28am

Thanks soooo much for this tutorial, it works great. Just one question: how did you get the navigation buttons next to the image instead of below?

Ki Kim's picture

by Ki Kim on Mon, 08/27/2012 - 10:02am

Layout and positioning is done by CSS.

by katbg (not verified) on Sun, 07/29/2012 - 7:51pm

sir, i would like to know if its possible to view the comments in each picture under the slideshow?

Ki Kim's picture

by Ki Kim on Mon, 08/27/2012 - 10:07am

I am not sure if it is a good idea to put comments under slideshow, since the slideshow looks good with fixed dimensions, and squeezing comments in it would be troublesome. Views does not seem to offer putting comments as one of fields out of the box.

Post new comment