Hi! I've embedded a view of images in a story node - actually the image_gallery view that comes bundled in the image module. I've used the following code which works in most cases:
$view = views_get_view('image_gallery');
$vout = $view->execute_display('items', array(NULL, $tid));
It works fine when there are 0 images in the gallery, and when there is more than 1 image. But if there is exactly 1 image, the image node is displayed and not the story node with the image gallery
So, the way I see it:
1. Is there any way in views of overriding the default views behaviour so it doesn't jump to the image node's page when it returns only 1 item?
2. If not, is there any way of getting a count of images returned by the view without actually using execute_display()? I can get the count of items with print_r(count($view->result)); but only after using execute_display and then it is too late and the single image node is displayed. So I guess I'm asking if there are any other methods exposed the $view class that will run the query without displaying the output?
Many thanks in advance!
Comments
Comment #1
dawehnerAre you really sure the display is called items? I guess it should be called default or something similar.
1) Can you please export the view, you didn't described how your view is described.
2) You can use pre_execute and execute. There nothing gets rendered.
Comment #2
badzilla commentedSorry, yes, I was playing around with different values and left items in there. It should be default.
2. I had a look at execute but it only returns TRUE or FALSE. I need something that returns an array to the sql output.
However, I have found my own solution. I can determine how many images there are in the gallery by reading the term_node table with the taxonomy api call taxonomy_select_nodes() function.
I am still curious though - is it possible to say to views - "If the resultset form the view is 1 DON'T jump straight to the image node. Still display the gallery with just 1 image in it."
I've attached the image_gallery view
Comment #3
dawehnerThe display name should be image_gallery_1