3

I am trying to create a slideshow of different Views.

I am thinking that the "view field" might work with "views slide show" - possibly sending the "view result counter" through as an argument. I am struggling though as I'm not sure this is a readable contextual filter when it reaches the "view field" view.

Can anyone point me in the right direction? If the "view result counter" is readable, what contextual filter should I add in the "view field" view.

3

Your current approach will not work because View Fields View will insert the same view for each and every row/slide.


Here is what you need to do. For example: You want 4 slides.

Create a Slideshow View of Articles or something that has 4 or more content. Then set the view results to 4, so it only shows 4.

Now add a Global: View Result Counter and exclude from display.

enter image description here

Add a Global: Custom Text and for text put:

[counter]

enter image description here

In your view preview you should see numbers

1
2
3
4

Now we are going to override these (the custom text), and replace them with views in template.php (located in /sites/all/themes/yourtheme/) add the following code:

function yourtheme_preprocess_views_view_fields($vars){

  if ($vars['view']->name == "view_slideshow_name" && $vars['fields']['nothing']->content == 1) {
    $vars['fields']['nothing']->content = views_embed_view('view_name', 'block_1'); 
  }
  else if ($vars['view']->name == "view_slideshow_name" && $vars['fields']['nothing']->content == 2) {
    $vars['fields']['nothing']->content = views_embed_view('view_name', 'block_2');
  }
  else if ($vars['view']->name == "view_slideshow_name" && $vars['fields']['nothing']->content == 3) {
    $vars['fields']['nothing']->content = views_embed_view('view_name', 'block_3');
  }
  else if ($vars['view']->name == "view_slideshow_name" && $vars['fields']['nothing']->content == 4) {
    $vars['fields']['nothing']->content = views_embed_view('view_name', 'block_4');
  }
}
  • replace yourtheme with the actual name of your theme
  • replace view_slideshow_name with the name of your view slideshow.
  • replace view_name with the name of the view that you want to show
  • replace block_1 with the machine name of your view

Lastly, in Drupal, clear/flush your Cache to see the changes.

Note: The changes will show up when you see the slideshow in your page and not in the view preview.


Forgot to mention that you need to uncheck provide/add wrappers and classes.

enter image description here

Also, for both of your fields, do as below

enter image description here

It seems odd that you have to list the block name of the view you want to insert but not the block name of the view you are overriding.

That's because in my case I did not plan to add more blocks or pages to my view. When you do not specify, it affects all pages or blocks that are from your view.

But if you want to be specific here is how:

function bartik_preprocess_views_view_fields($vars){ 

  if ($vars['view']->name == "rotator" && $view->current_display == 'block_1' && $vars['fields']['nothing']->content == 1) { 

    $vars['fields']['nothing']->content = views_embed_view('checking_home', 'block_1'); 
    } 

  else if ($vars['view']->name == "rotator" && $view->current_display == 'block_1' && $vars['fields']['nothing']->content == 2) { 

    $vars['fields']['nothing']->content = views_embed_view('home_outstanding_issues', 'block'); 
    } 

} 
  • Hi, many thanks for you response. I have been tinkering but cant get it to work. this is what I have added in the template.php function bartik_preprocess_views_view_fields($vars){ if ($vars['view']->name == "rotator" && $vars['fields']['nothing']->content == 1) { $vars['fields']['nothing']->content = views_embed_view('checking_home', 'block_1'); } else if ($vars['view']->name == "rotator" && $vars['fields']['nothing']->content == 2) { $vars['fields']['nothing']->content = views_embed_view('home_outstanding_issues', 'block'); } } Does anything look incorrect? – user30505 Jun 17 '16 at 10:51
  • function bartik_preprocess_views_view_fields($vars){ if ($vars['view']->name == "rotator" && $vars['fields']['nothing']->content == 1) { $vars['fields']['nothing']->content = views_embed_view('checking_home', 'block_1'); } else if ($vars['view']->name == "rotator" && $vars['fields']['nothing']->content == 2) { $vars['fields']['nothing']->content = views_embed_view('home_outstanding_issues', 'block'); } } – user30505 Jun 17 '16 at 11:14
  • @user30505 your code looks good to me, did you remember to flush the cache? – No Sssweat Jun 17 '16 at 14:26
  • sorry, I'm still struggling to get it working :-( I would love to help out and identify what I have wrong but as I have zero PHP experience I am of little help here. It seems odd that you have to list the block name of the view you want to insert but not the block name of the view you are overriding. I am using panels and a sub theme but I don't think this makes a difference. I tried removing the sub theme and using a "page" view of the slide show but still no joy. – user30505 Jun 18 '16 at 8:33
  • 1
    Thanks loads, working great, very much appreciate your comments and assistance. X – user30505 Jun 22 '16 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.