Hi,

I've been trying this for a couple of days now, but can't figure out how..

I want to create a view (as a block) that displays all albums added. I Only want to show the cover image and the gallery/album title.

Could anyone please guide me how to do this?

Thanks alot.

CommentFileSizeAuthor
#6 gallery_block.txt2.61 KBdbeall
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rik’s picture

Hi Cholden,
Here you've got an example. Use the Views import functionality to import it.

$view = new view;
$view->name = 'all_gallery_thumbnails';
$view->description = 'A tumbnail grid with all gallery cover images';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '<strong>[title]</strong>',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Overrite',
    ),
  ),
  'gid' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'node_gallery_setting' => 'node_gallery_gallery',
    'exclude' => 0,
    'id' => 'gid',
    'table' => 'node_galleries_gallery',
    'field' => 'gid',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Overrite',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'time',
  'results_lifespan' => '3600',
  'output_lifespan' => '3600',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 1);
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
  'grouping' => '',
  'columns' => '4',
  'alignment' => 'horizontal',
));
$handler->override_option('row_options', array(
  'inline' => array(),
  'separator' => '',
  'hide_empty' => 0,
));
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->override_option('pane_title', '');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
  'name' => 'View panes',
  'weight' => 0,
));
$handler->override_option('allow', array(
  'use_pager' => FALSE,
  'items_per_page' => FALSE,
  'offset' => FALSE,
  'link_to_view' => FALSE,
  'more_link' => FALSE,
  'path_override' => FALSE,
  'title_override' => FALSE,
  'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array());
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
$handler = $view->new_display('block', 'Blok', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
dbeall’s picture

I will stick my nose in here for a second...
The above code uses panels and/or panes. To use the code without those, take this part out

$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->override_option('pane_title', '');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
  'name' => 'View panes',
  'weight' => 0,
));

Adjust the grid settings to suit your needs.
You can also add a 'page' view and a path after import to make a page.

cholden’s picture

Thanks for your replys.

I've imported the views-code which went fine. It also shows the galleries. The only problem is that it show each gallery the same mount of times as the number is images in each gallery.

I got two galleries (Test galleri & Reference galleri) with 5 images in each gallery.

Here's the result: http://grab.by/Jn3

I'm using the lastest version (6.x-2.0-alpha11)

Thanks.

dbeall’s picture

on the view, check to see that 'Distinct' is set to 'yes'

EDIT: BTW, you can also add a 'page' view to that and add a 'path' if you like.

cholden’s picture

Distinct is set to yes.

And for my purpose block would be the best solution. But thanks for pointing it out anyway.

Here's a screenshot of my settings.
http://grab.by/Kij

dbeall’s picture

FileSize
2.61 KB

I have double checked this views code with an import and it works fine..
This is the same as the above, but it's in a normal block format(vertical unformatted).
The panels parts is removed..

cholden’s picture

Thats really weird.

I just importet the code in the .txt file, and i get the same result as before.

I've deleted the old images and galleries and created two new galleries (Album1 & Album2) with 9 & 5 images in. But still the same result.

http://grab.by/KqE

I really dont get why it creates an album for each image in the album..

dbeall’s picture

yes it is really weird.. for some reason the distinct setting in views is not working.
others have been finding this.. I posted a subscribe post in case something pops up..
http://drupal.org/node/140061 ;Node Distinct is not working anymore

Rik’s picture

I imported the view again and it does show all thumbs from all galleries only one time. I'm using version 6.x-2.0-alpha11. Can it be you have not selected cover images? Because the view uses the coverimages.

dbeall’s picture

@Rik, I used your code, just changed it a little trying to invoke a change that will wake it up. I have worked with your code and it seems to be just fine on my end.

duplicate issue, different views code:
http://drupal.org/node/640548 ;Gallery duplicates due to views distinct not working

Rik’s picture

I'm suspecting that cholden needs to select a coverimage for each gallery.

dbeall’s picture

@Rik,, you think he is letting the default take over for the cover image.. Instead of actually choosing or selecting one..?
interesting.. hmmm

EDIT: I'm using views 6.x-2.7

Rik’s picture

For the record I'm using Views version 6.x-3.0-alpha1.

Rik’s picture

That's indeed what I think, perhaps something going wrong with that. I know I selected all my cover images manually. Also the Views issue you are referring to is for version 5 of drupal and from 2007, I can't imagine its still broken :)

cholden’s picture

I just selected new cover images for by albums instead of the default ones. Result is the same.

Maybe I should try another version of views? The 6.x-2.7 perhaps?

It seems like the 'Distinct' function is ignored.

cholden’s picture

Oh.

I just checked the changelog in the views folder, and I had 6.x-2.7. I just updated to the newest version 6.x-3.0-alpha1.

Doing this, solved my problem and made me happy.
Woohoo.

Thanks alot for your advices, suggestions and overall help.

http://grab.by/KEY

Love from Casper to helpers!

cholden’s picture

Aye.

I got a bonus-question.

How do I exclude one specific gallery?

dbeall’s picture

Status: Active » Closed (fixed)

you can use a filter by "Title" to exclude one gallery

this issue has been solved.. great ! --closed

cholden’s picture

Status: Closed (fixed) » Fixed
dbeall’s picture

Status: Fixed » Closed (fixed)

Edit: your right, I lost track of where this started... sorry

some views code was supplied by Rik..

added to handbook style views and theming:
http://drupal.org/node/544748