views

Drupal Views Group by Field with Counts and Links - A Better Way

Alas, I came across a better way to take a bunch of rows from views, group them by a particular field, and provide a count for each.

Here is a basic example for Drupal 6 (probably very similar for Drupal 7).

Basic Settings

Style: HTML List

Fields

Node id (exclude from display)

Node title

Arguments

Node title

Drupal Views Group by Field with Counts

Note, since writing this article I learned about Views Arguments 'action to take if argument not present' summary list with counts... it is definitely easier than the approach I documented below. I'll leave what I have done below because I'm not sure the summary list option will handle all cases. Someday I'll update this post to include a tutorial on how to use the aformentioned approach, someday.

Drupal How to Theme a Views Exposed Filter Form

To theme the exposed filter form on a view in Drupal:


  1. Copy sites/all/modules/views/theme/views-exposed-form.tpl.php to sites/all/themes/MY_THEME/views-exposed-form--MY-VIEW-NAME.tpl.php
  2. Use the views admin UI to rescan the template files
    • Basic Settings -> Theme Information -> Rescan Template Files
    • Note: it won't show your new template file in the list
  3. Save your view

If you need more fine tuned methods of modifying the actual form, then use hook_form_alter instead.

Programmatically Display a Certain Page of Data with Drupal Views

Here is how you can programmatically load a Drupal view, then specify a particular page of data to show, then print out the view.

$what_page_to_show = 10;
$view = views_get_view('my_example_view');
$view->pager['current_page'] = $what_page_to_show;
print $view->preview();
Subscribe to RSS - views