User login

Change the number of columns in a grid view

You may be asking yourself: why did I find this information at some site called Agaric Design Collective? Beats us. If you can find the right place in the Drupal handbook (drupal.org/handbook) for this information, please put it there!

Looking at the code of views_bonus_grid.module:

  // set default count.

  $cols = $view->gridcount ? $view->gridcount : 4;

It would seem that putting

$view->gridcount = 2;

(replace two with your chosen number)

into "Argument Handling Code," "Argument Code:"

will do what we want.

Again, note this is for number of columns (the vertical things). The number of rows (those horizontal things) will be determined by the number of nodes you choose to display (divided by columns).

print_r($view) is recommended by Lullabotters.
http://www.lullabot.com/audiocast/podcast-50-drupal-tips-and-tricks (text below)

But it seems it needs to be wrapped in a drupal_set_message to work:

<?php
  global $user; if ($user->uid==1) drupal_set_message('<pre>' . print_r($view, TRUE) . '</pre>');
?>

Lullabot's tips:

Views

32. Use theme('view', {arguments}) to embed a view anywhere in your theme's template.php or .tpl.php files
33. Use the custom argument handling code in a View to change anything about a view: filters, number displayed, fields, and of course arguments. You can alter these items with or without conditionals. Change the number of columns in a grid view; change the number of items that appear if the "feed" argument is present; etc... (see #36 to see the view object)
34. Use "promote to front page" / "sticky" to do other things using Views... see also Views Bookmarks - http://drupal.org/node/49075
35. Use Views + Taxonomy - http://drupal.org/project/taxonomy_redirect
Redirect to use a custom view for each vocabulary's listing pages.
36.

Use print_r($view) inside the 'Argument code' field of a View to see the view object. see #33 (oops)
37. Give any number of 'block'-only views the same page URL, and their [more] links will all point to the same page.

Agaric's comment:

Use drupal_set_message with print_r to see the view code

Specifically, put this in the custom argument code:

drupal_set_message

To do this on a live site without regular folks seeing, while you're online as user #1, you can use this:

global $user; if ($user->uid==1) drupal_set_message('<pre>' . print_r($view, TRUE) . '</pre>');

(Note: Agaric Design Collective would never, ever, ever do debugging or development on live site. Ever. Well maybe sometimes.)

Not that I'm finding the output all that helpful. This didn't help the grid view number of columns question at all (since it handles it by declaring a default if not defined specially as an argument, there's no argument or anything to take as an example). Had to look in the module's code for that.

stdClass Object
(
[vid] => 40
[name] => participants
[description] => public participants
[access] => Array
(
)

[page] => 1
[page_title] => WSF2008 Participants
[page_header] =>
[page_header_format] => 1
[page_empty] =>
[page_empty_format] => 1
[page_footer] =>
[page_footer_format] => 1
[page_type] => bonus_grid
[use_pager] => 1
[nodes_per_page] => 100
[url] => view/participants
[menu] => 1
[menu_tab] => 0
[menu_tab_weight] => 0
[menu_title] =>
[menu_tab_default] => 0
[menu_tab_default_parent_type] => tab
[menu_parent_title] =>
[menu_parent_tab_weight] => 0
[block] => 0
[block_title] =>
[block_use_page_header] => 0
[block_header] =>
[block_header_format] => 1
[block_use_page_footer] => 0
[block_footer] =>
[block_footer_format] => 1
[block_use_page_empty] => 0
[block_empty] =>
[block_empty_format] => 1
[block_type] => node
[nodes_per_block] => 0
[block_more] => 0
[breadcrumb_no_home] => 0
[changed] => 1197026551
[view_args_php] => drupal_set_message('View:

' . print_r($view, TRUE) . '

');
[is_cacheable] => 0
[sort] => Array
(
)

[argument] => Array
(
)

[field] => Array
(
[0] => Array
(
[vid] => 40
[tablename] => usernode_users
[field] => name
[label] =>
[handler] => usernode_views_handler_field_username_link
[sortable] => 1
[defaultsort] => ASC
[options] =>
[position] => 0
[fullname] => usernode_users.name
[id] => usernode_users.name
[queryname] => usernode_users_name
)

[1] => Array
(
[vid] => 40
[tablename] => usernode_users
[field] => created
[label] =>
[handler] => views_handler_field_date_small
[sortable] => 1
[defaultsort] => 0
[options] =>
[position] => 1
[fullname] => usernode_users.created
[id] => usernode_users.created
[queryname] => usernode_users_created
)

)

[filter] => Array
(
[0] => Array
(
[vid] => 40
[tablename] =>
[field] => node.type
[value] => Array
(
[0] => usernode
[1] => organization
)

[operator] => OR
[options] =>
[position] => 0
[id] => node.type
)

[1] => Array
(
[vid] => 40
[tablename] =>
[field] => node.status
[value] => 1
[operator] => =
[options] =>
[position] => 1
[id] => node.status
)

)

[exposed_filter] => Array
(
)

[build_type] => page
[type] => bonus_grid
)

Resolution

Searched words: 
drupal views grid view argument columns show information about a view override set columns bonus pack grid view

Comments

just to say this can now be done

by adding:

$view->gridcount = SOME_NUMBER;

into the views argument code section

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.