You are here

README.txt in Views Global Filter 7

Same filename and directory in other branches
  1. 8 README.txt
  2. 6 README.txt
GLOBAL FILTER FOR VIEWS & CONTEXTS (D7)
=======================================

This module remembers your visitors' filter settings while they are on your site
and beyond (i.e. until they return). The filter settings can be used to filter
views across multiple pages and to switch "contexts", like page layouts, see
http://drupal.org/project/context.
 
Global Filter takes advantage of the small Session Cache API module,
http://drupal.org/project/session_cache. Please enable it. Its out-of-the-box
configuration is fine for now.

The values that may be selected from a global filter are based on either a field
or a view. A search term text box may also be used as a global filter. It is
treated like a field. If you have the Location or Geofield modules installed
then you may also globally filter by proximity. See the special section below
for details.
Fields execute just that little faster and are more straight-forward to use than
views, so pick a field as your global filter unless you want to reduce the set
of field values that may be selected, in which case you'll generally have to
resort to a view.

Fields are defined on the Structure >> Content types >> Manage fields and
Configuration >> Account settings >> Manage fields pages. An overview of all
fields on your system can be viewed via a link on the Administer >> Reports
page.

GLOBAL FILTER FOR VIEWS
=======================
1) A couple of filter blocks, named "Global filter block 1" and "Global filter
block 2" will now be available at Structure >> Blocks. If you want to use more
than two global filter blocks, you can create more blocks at Configuration >>
Global Filter. Place the block or blocks anywhere on your site.

2a) You may use either a field or the output of a view to drive a global filter.
Use the radio buttons on the block configuration page to select which one and
inspect the drop-down to see the fields available for use. If none of the node
properties/fields match what you're after, use a view. If you decide on a view
to populate the global filter, make sure that in the driving view the Format is
set to Unformatted and select "Show: Fields". Be aware that it will be the first
item under the view's Fields heading that will populate the filter widget, so
re-order your items if necessary. The remaining items will be ignored. The view
does not need to have a page or block display associated with it and may even
be disabled -- it will still operate correctly as a global filter.
2b) After you have selected a widget, press "Save block". The page will refresh
and you will be able to add more filters to the same block by opening the next
field set under the one just saved.
2c) After saving the block you can also select global filter defaults. The
default will remain active until the user makes a different filter selection. If
the global filter is a field that also appears on user profiles, then
authenticated users can override the global filter default with their personal
choice on their profile.

3) With your global filter block(s) configured, you can now use them to channel
the selected values into a view's Contextual Filter (as opposed to a regular
filter).
On the View edit page, open the Advanced field-set on the right. Then next to
Contextual Filters click Add and select the item corresponding to the global
filter source in the previous step. If you selected a View in step 2) then tick
a suitable ID option, e.g. if the view outputs taxonomy terms, then tick
"Taxonomy: Term ID" (not "Taxonomy: Term", i.e not the name/description).
After pressing "Add and configure..." on the next panel, press the radio button
"Provide default value".
3a) When you chose a field as the source for the global filter, select Type
"Global filter (field or search term)".
3b) When you chose a View as the source for the global filter, select Type
"Global filter (view)" and then select the View(s) driving this filter.

4) Apply and Save the view.

That's it. Repeat steps 3) and 4) for the remaining views that need to use your
global filters.

Make sure that under "Page Settings" the Path does NOT contain percent signs for
arguments that you wish to apply a Global Filter to. In other words, the percent
signs in the Path should stop at the first Global Filter. So, if you have one
normal contextual filter, followed by one global filter, you'll have one percent
sign. When typing the view's path in your browser address bar, append arguments
for the normal contextual filters that precede the global filter. Use "all" to
skip a filter: /your-view-with-contextual-filters/all. If you type a URL
argument in the position of a global filter, you temporarily override the
current global filter value without setting it.

By default each global filter widget comes with a Set button to activate the
selection. However if you tick the appropriate check-box on the filter's
block page, the Set button does not appear and the filter is activated
immediately upon release of the mouse button.

In addition to the regular widgets you can also place links of the form
"/somepage?field_myfield=10" anywhere on your site, e.g. in menus, to set
global filters. You can set multiple values too, by separating them by commas:
"/somepage?field_myfield=10,17". You can also insert these links on other sites
or in emails to direct the reader to a pre-filtered view of your site.

You can have a total of up to 20 global filters across 1-20 global filter
blocks.

GLOBAL FILTER TO SET CONTEXTS
=============================
Instead of using a global filter to simultaneously filter views, you can use it
with the Context module, http://drupal.org/project/context, as a condition for
setting contexts.
For instance you can create a global filter block with a drop-down of
countries and then create session conditions for various country names, so that
your site reacts to the globally selected country. And using a PHP code snippet
for the default you could pre-select the drop-down with the visitor's country
based on their IP address, via http://drupal.org/project/smart_ip. See:
http://drupal.org/node/2318193

To set up a session condition you need to install and enable Session Context,
http://drupal.org/project/session_context.
Then at admin/structure/context/settings/session, use the following format to
create a condition: global_filter:field_NAME=VALUE  (no spaces, except in VALUE)
This condition will then be available at /admin/structure/context/add, when you
select Session as the condition from the drop-down.

For instance, to make the Context module react to taxonomy term 21 being
globally selected by the visitor, enter in the text area at
admin/structure/context/settings/session:
  global_filter:field_tags=21
Ignore the note below the text area.
You can require multiple values being set on the filter by using a comma:
   global_filter:field_tags=21,36,9
This means: react with the selected context only when all three taxonomy terms
are selected in a multi-valued widget, like a combo-box or check boxes.
You can achieve OR-logic (i.e. "one of") by adding single-valued session
conditions separately:
  global_filter:field_tags=21
  global_filter:field_tags=36

CAVEAT: the Context Session module currently does not support any of the caching
options available through Session Cache API, except for "session". Verify that
at admin/config/development/session_cache, the radio button "on the server,
in $_SESSION memory" is pressed, when you use Context Session.

GLOBAL FILTER TAXONOMY WITH HIERARCHICAL SELECT
===============================================
If you wish to use the taxonomy selection widget provided by the Hierarchical
Select module, you can. When configuring the Hierarchical Select widget on the
field, you will be prompted to press either "Save term lineage" or "Save only
the deepest term". Both work with Global Filter, but "Save term lineage"
gives you greater flexibility when using the hierarchical select as the widget
for your global filters.
Say you have a three-tiered taxonomy of Country, State and City and created a
field for it on some content type. If you created a piece of content with
"Australia, Victoria, Melbourne" as the taxonomy lineage on the field, then that
content will be returned in the view results when the global filter is set to
either just "Australia" or "Australia, Victoria" or "Australia, Victoria,
Melbourne". With "Save only the deepest term" pressed on the widget
configuration page that content will only be returned when the global filter is
set to "Australia, Victoria, Melbourne".
When you use the Hierarchical Select widget you do NOT need to tick "Allow
multiple values" on the contextual filter configuration panel.

GLOBAL FILTER FOR DATES OR DATE RANGES
======================================
The "created (posted)" and "updated (modified)" node PROPERTIES are
architecturally different from Date FIELDS (discussed below). When used as
contextual filters "created" and "updated" are supported as single values only.
However you can use them as contextual ranges via the Views Contextual Range
Filter module. When used this way, you can enter ranges for "created" and
"updated" dates via the Range widget in Global Filter.

As far as general date FIELDS go, here is how it works.
We assume that in addition to Views you have the Date module enabled. If your
content does not already have a date field attached, add one as per normal via
the Manage Fields tab on the content type page. You may pick any of the three
Date types, i.e. plain, ISO or Unix Timestamp. Just be aware of this bug
in the Date module: drupal.org/project/node/1477180. So until this is fixed,
maybe avoid Unix Timestamp. When prompted pick any of the available date
selection widgets, e.g popup calendar or the triple select list. You may tick
the "Collect an End date" box too, if you wish. After you have configured on
the block configuration page a global filter for the selected date field or
range, the global filter will render itself using the same widget you picked for
the field on the content type. However, the global filter will always appear as
a date range. Filtering on a single date would be a little restrictive!
Finally, as with any other global filter you need to hook it into your view as
a contextual filter. Use either just the field start date or create a second
contextual filter to also require the content's end date being inside the
filter range. In either case scroll down the bottom of the contextual filter
panel to the heading "Dates to compare". Press the button "Only this field".

GLOBAL FILTER FOR SEARCH TERMS
==============================
To configure a global filter as a global keyword search, select as the driver
the pseudo-field "Search: Search terms". The widget will always be a text field
regardless of which radio button you press.
In your View, after pressing "Add" in the Contextual Filter tick the check box
"Search: Search terms", followed as per usual by the "Provide default value"
radio button. Select "Global filter (field or search terms)" from the drop-down.
Press Apply at the bottom of the panel.
If you have the Search API module enabled the process is the same.

GLOBAL FILTER FOR RANGES
========================
With the "Contextual Range Filter" module enabled and your contextual filter
converted to a contextual range filter, you may use any of the following
widgets to enter filter ranges as opposed to single filter values:
o text field, enter ranges by separating "from" and "to" by a double hyphen,
  for example 0.5--2.5 or a--k or, if the field is a list, use either the keys,
  e.g., 3--7 or the list names, e.g. toddler--teenager
o range, i.e. separate "from" and "to" text fields, no need to enter the
  separator
o inherit range slider (requires the Slide with Style module from the project
  http://drupal.org/project/select_with_style)

GLOBAL FILTER FOR PROXIMITY USING LOCATION MODULE
=================================================
If you have the Location module enabled you can globally filter content or user
accounts based on a distance from a postcode or lat/lon pair of coordinates
as entered by the visitor.
If you wish to base proximity on a postcode the visitor enters, then make sure
that you are connected to the Internet and have selected an appropriate web
service on the Location configuration page
admin/config/content/location/geocoding.
When using the Google geocoding service entering a blank API key usually works.
To configure the global filter block select as the driver the pseudo-field
"Location module: Distance/Proximity". The widget in this case will be a single
text field -- for an alternative option, see the next section.
As far as the Contextual Filter in Views is concerned, tick "Provide default
value" as per normal, then select "Global filter (proximity)" and enter a
default distance. Scroll down the panel to select whether you want the user to
enter a lat,long pair or a postcode in the global filter text field. Also select
the unit (km or mile) and the shape of the proximity area (circular or
rectangular). Press Apply at the bottom and you're done.
The proximity filter presents itself as a textfield for the visitor to enter
their postcode or lat/lon pair (separated by a comma). Visitors may optionally
append a space or underscore and a distance. If the distance is omitted, then
the default as set on the Views "Global filter (proximity)" configuration panel
is taken.
If you have "IP Geolocation Views and Maps" enabled then you can set as an
initial default the postal code to that of the visitor's location upon first
visit. To do this enter this code snippet as the global filter global default:

<?php
  $location = ip_geoloc_get_visitor_location();
  return $location['postal_code'];
?>

GLOBAL FILTER FOR ADDRESS OR VISITOR'S LOCATION (GEOFIELD, LOCATION MODULES)
============================================================================
To configure the global filter block for use with the Location module select as
before as the driver the pseudo-field "Location module: Distance/Proximity".
When using Geofield, select the name of the correct field from the drop-down.
For the widget select "Proximity (reference location and distance)".
The widget renders as a small form with two fields. The first is to specify a
distance, in km or miles as configured on the Views contextual filter UI panel.
The second field when left blank will default to the user's current position
as retrieved by module IPGV&M (drupal.org/project/ip_geoloc), if enabled. If
an address or approximate address, like "Melbourne, Australia" is entered, then
the Google geocoding service will be used to obtain lat/lon. This requires the
Geocoder module.

GLOBAL FILTER FOR CITY, NOT USING LOCATION OR GEOFIELD MODULES
==============================================================
Here are three examples. For an IP-based lookup of the visitor's location
configure either Smart IP or GeoIP API. For an HTML5 (i.e GPS) location based
approach also configure IPGV&M. We assume that you have already defined a
field named "City" (field_city) on one or more of your content types. This
field may be either a text field or taxonomy term reference.
At /admin/structure/block find a block named "Global filter block # (not
configured)". Press "configure".
Enter <none> in the "Block title" box.
In the dropdown "Choose the field to be used as a global filter" find your
city field: "Field: City (field_city)". Widget: "Inherit from field".
Under "Alternatively specify a default through PHP code" enter a code snippet
as per below.
When using Smart IP, enter:
  <?php return $_SESSION['smart_ip']['location']['city']; ?>

When using GeoIP API enter:
  <?php $loc = geoip_city(); return empty($loc) ? 'default' : $loc->city; ?>

Or when using IPGV&M:
  <?php $loc = ip_geoloc_get_visitor_location(); return $loc['locality']; ?>

For the "Region setting" select "Content". Finally press "Show block only on the
listed pages" and enter the path to your View. Click "Save block".
Now go back to edit your View.
In the "Advanced" fieldset on the right "Add" a Contextual Filter for "Content:
City (field_city)". On the next panel press "Provide default value", then for
the Type select "Global filter (field or search terms)". Click "Apply".
Save the View.
That should be it. Log out. Go to the URL associated with the View and it
should be filtered by your city. You should also see a text box there to filter
the View by any city you type. This should work for both logged-in and anonymous
users. A further option is that if the same field_city is also added to the user
profile at admin/config/people/accounts/fields, (e.g. "My favourite city"), then
the value entered by the account holder on the "Edit account" page will become
the initial value of the exposed filter.
Note: this solution may not work when you're not connected to the Internet and
your IP address is "localhost", 127.0.0.1.

USEFUL VIEW OPTIONS
===================
On the View edit page, in the contextual filter configuration panel, after you
have selected a global filter to provide the default value, scroll down the
panel and expand the More field-set for a couple of additional useful options.
"Allow multiple values" is MANDATORY when you configured your global filter to
render as a multi choice widget.
"Exclude" is nice to populate a view with the compliment of the global filter
selection (e.g. all countries except South American countries).

ADVANCED OPTIONS: ROTATING BLOCK CONTENT
========================================
A special auto-cycle filter is available under the "Advanced configuration"
fieldset on the Configuration >> Global Filter page. You can use this to create
block content that changes with every click on the site. Examples are ads, news
items or user profile pictures, that have to follow a specific logical sequence,
for instance chronological, alphabetical, by section or chapter number, or by
vocabulary term order.

You normally need two views for this (although at the bottom of this page we'll
mention a short-cut alternative for the second view). Let's call these the
filter view and the block/page view.

The filter view simply needs to return in the desired order, the nodes (or
users or etc.) that you wish to rotate through the block. This view does not
need page or block displays and doesn't have to output any fields, as the nids
are silently output anyway. However, to verify the view correctly returns the
nodes in the order you wish them to cycle through the block, we suggest to
configure the view format to output titles or teasers. Save this view.
Activate this view as the driver for the auto-cycle filter at Configuration >>
Global Filter, opening the "Advanced configuration" fieldset. Select the view
you've just created and press "on every page load".

The block/page view needs to produce at least as much content as the filter
view. In fact you could start by cloning the filter view and use it as a base.
Select any display format and any fields you like to display for the block of
rotating content. Don't forget to add a block or page display to this view!
Remember that only one of these pieces of content will be shown at any one time,
as auto-selected by the above filter view. This is established by adding a
Contextual Filter to the block/page view (Advanced fieldset, upper right
corner). Tick "Content: Nid" and "Apply...". Press "Provide default value" and
then select "Global filter (view)" from the Type drop-down. Your auto-cycle view
should appear in the next drop-down. Press "Apply...". Save this view.

Finally, if you went for a view with a block rather than page display at
Structure >> Blocks, move your block from the Disabled section into the desired
page region.

Verify the view appears and note that with every new page you visit the
page/block view displays another piece of content.

Shortcut: if you're happy to have just the title show in the block, you could
do the following. Don't create a second view. Create a block instead, select
"PHP code" for the block text format and enter in the block body text area:

<?php
  $node = node_load(global_filter_get_session_value('view_autocycle'));
  print theme('node', array('elements' => array('#node' => $node, '#view_mode' => 'teaser')));
?>

Depending on how your theme's node.tpl.php is organised this will most likely
show just the hyperlinked title of the next piece of auto-selected content.

File

README.txt
View source
  1. GLOBAL FILTER FOR VIEWS & CONTEXTS (D7)
  2. =======================================
  3. This module remembers your visitors' filter settings while they are on your site
  4. and beyond (i.e. until they return). The filter settings can be used to filter
  5. views across multiple pages and to switch "contexts", like page layouts, see
  6. http://drupal.org/project/context.
  7. Global Filter takes advantage of the small Session Cache API module,
  8. http://drupal.org/project/session_cache. Please enable it. Its out-of-the-box
  9. configuration is fine for now.
  10. The values that may be selected from a global filter are based on either a field
  11. or a view. A search term text box may also be used as a global filter. It is
  12. treated like a field. If you have the Location or Geofield modules installed
  13. then you may also globally filter by proximity. See the special section below
  14. for details.
  15. Fields execute just that little faster and are more straight-forward to use than
  16. views, so pick a field as your global filter unless you want to reduce the set
  17. of field values that may be selected, in which case you'll generally have to
  18. resort to a view.
  19. Fields are defined on the Structure >> Content types >> Manage fields and
  20. Configuration >> Account settings >> Manage fields pages. An overview of all
  21. fields on your system can be viewed via a link on the Administer >> Reports
  22. page.
  23. GLOBAL FILTER FOR VIEWS
  24. =======================
  25. 1) A couple of filter blocks, named "Global filter block 1" and "Global filter
  26. block 2" will now be available at Structure >> Blocks. If you want to use more
  27. than two global filter blocks, you can create more blocks at Configuration >>
  28. Global Filter. Place the block or blocks anywhere on your site.
  29. 2a) You may use either a field or the output of a view to drive a global filter.
  30. Use the radio buttons on the block configuration page to select which one and
  31. inspect the drop-down to see the fields available for use. If none of the node
  32. properties/fields match what you're after, use a view. If you decide on a view
  33. to populate the global filter, make sure that in the driving view the Format is
  34. set to Unformatted and select "Show: Fields". Be aware that it will be the first
  35. item under the view's Fields heading that will populate the filter widget, so
  36. re-order your items if necessary. The remaining items will be ignored. The view
  37. does not need to have a page or block display associated with it and may even
  38. be disabled -- it will still operate correctly as a global filter.
  39. 2b) After you have selected a widget, press "Save block". The page will refresh
  40. and you will be able to add more filters to the same block by opening the next
  41. field set under the one just saved.
  42. 2c) After saving the block you can also select global filter defaults. The
  43. default will remain active until the user makes a different filter selection. If
  44. the global filter is a field that also appears on user profiles, then
  45. authenticated users can override the global filter default with their personal
  46. choice on their profile.
  47. 3) With your global filter block(s) configured, you can now use them to channel
  48. the selected values into a view's Contextual Filter (as opposed to a regular
  49. filter).
  50. On the View edit page, open the Advanced field-set on the right. Then next to
  51. Contextual Filters click Add and select the item corresponding to the global
  52. filter source in the previous step. If you selected a View in step 2) then tick
  53. a suitable ID option, e.g. if the view outputs taxonomy terms, then tick
  54. "Taxonomy: Term ID" (not "Taxonomy: Term", i.e not the name/description).
  55. After pressing "Add and configure..." on the next panel, press the radio button
  56. "Provide default value".
  57. 3a) When you chose a field as the source for the global filter, select Type
  58. "Global filter (field or search term)".
  59. 3b) When you chose a View as the source for the global filter, select Type
  60. "Global filter (view)" and then select the View(s) driving this filter.
  61. 4) Apply and Save the view.
  62. That's it. Repeat steps 3) and 4) for the remaining views that need to use your
  63. global filters.
  64. Make sure that under "Page Settings" the Path does NOT contain percent signs for
  65. arguments that you wish to apply a Global Filter to. In other words, the percent
  66. signs in the Path should stop at the first Global Filter. So, if you have one
  67. normal contextual filter, followed by one global filter, you'll have one percent
  68. sign. When typing the view's path in your browser address bar, append arguments
  69. for the normal contextual filters that precede the global filter. Use "all" to
  70. skip a filter: /your-view-with-contextual-filters/all. If you type a URL
  71. argument in the position of a global filter, you temporarily override the
  72. current global filter value without setting it.
  73. By default each global filter widget comes with a Set button to activate the
  74. selection. However if you tick the appropriate check-box on the filter's
  75. block page, the Set button does not appear and the filter is activated
  76. immediately upon release of the mouse button.
  77. In addition to the regular widgets you can also place links of the form
  78. "/somepage?field_myfield=10" anywhere on your site, e.g. in menus, to set
  79. global filters. You can set multiple values too, by separating them by commas:
  80. "/somepage?field_myfield=10,17". You can also insert these links on other sites
  81. or in emails to direct the reader to a pre-filtered view of your site.
  82. You can have a total of up to 20 global filters across 1-20 global filter
  83. blocks.
  84. GLOBAL FILTER TO SET CONTEXTS
  85. =============================
  86. Instead of using a global filter to simultaneously filter views, you can use it
  87. with the Context module, http://drupal.org/project/context, as a condition for
  88. setting contexts.
  89. For instance you can create a global filter block with a drop-down of
  90. countries and then create session conditions for various country names, so that
  91. your site reacts to the globally selected country. And using a PHP code snippet
  92. for the default you could pre-select the drop-down with the visitor's country
  93. based on their IP address, via http://drupal.org/project/smart_ip. See:
  94. http://drupal.org/node/2318193
  95. To set up a session condition you need to install and enable Session Context,
  96. http://drupal.org/project/session_context.
  97. Then at admin/structure/context/settings/session, use the following format to
  98. create a condition: global_filter:field_NAME=VALUE (no spaces, except in VALUE)
  99. This condition will then be available at /admin/structure/context/add, when you
  100. select Session as the condition from the drop-down.
  101. For instance, to make the Context module react to taxonomy term 21 being
  102. globally selected by the visitor, enter in the text area at
  103. admin/structure/context/settings/session:
  104. global_filter:field_tags=21
  105. Ignore the note below the text area.
  106. You can require multiple values being set on the filter by using a comma:
  107. global_filter:field_tags=21,36,9
  108. This means: react with the selected context only when all three taxonomy terms
  109. are selected in a multi-valued widget, like a combo-box or check boxes.
  110. You can achieve OR-logic (i.e. "one of") by adding single-valued session
  111. conditions separately:
  112. global_filter:field_tags=21
  113. global_filter:field_tags=36
  114. CAVEAT: the Context Session module currently does not support any of the caching
  115. options available through Session Cache API, except for "session". Verify that
  116. at admin/config/development/session_cache, the radio button "on the server,
  117. in $_SESSION memory" is pressed, when you use Context Session.
  118. GLOBAL FILTER TAXONOMY WITH HIERARCHICAL SELECT
  119. ===============================================
  120. If you wish to use the taxonomy selection widget provided by the Hierarchical
  121. Select module, you can. When configuring the Hierarchical Select widget on the
  122. field, you will be prompted to press either "Save term lineage" or "Save only
  123. the deepest term". Both work with Global Filter, but "Save term lineage"
  124. gives you greater flexibility when using the hierarchical select as the widget
  125. for your global filters.
  126. Say you have a three-tiered taxonomy of Country, State and City and created a
  127. field for it on some content type. If you created a piece of content with
  128. "Australia, Victoria, Melbourne" as the taxonomy lineage on the field, then that
  129. content will be returned in the view results when the global filter is set to
  130. either just "Australia" or "Australia, Victoria" or "Australia, Victoria,
  131. Melbourne". With "Save only the deepest term" pressed on the widget
  132. configuration page that content will only be returned when the global filter is
  133. set to "Australia, Victoria, Melbourne".
  134. When you use the Hierarchical Select widget you do NOT need to tick "Allow
  135. multiple values" on the contextual filter configuration panel.
  136. GLOBAL FILTER FOR DATES OR DATE RANGES
  137. ======================================
  138. The "created (posted)" and "updated (modified)" node PROPERTIES are
  139. architecturally different from Date FIELDS (discussed below). When used as
  140. contextual filters "created" and "updated" are supported as single values only.
  141. However you can use them as contextual ranges via the Views Contextual Range
  142. Filter module. When used this way, you can enter ranges for "created" and
  143. "updated" dates via the Range widget in Global Filter.
  144. As far as general date FIELDS go, here is how it works.
  145. We assume that in addition to Views you have the Date module enabled. If your
  146. content does not already have a date field attached, add one as per normal via
  147. the Manage Fields tab on the content type page. You may pick any of the three
  148. Date types, i.e. plain, ISO or Unix Timestamp. Just be aware of this bug
  149. in the Date module: drupal.org/project/node/1477180. So until this is fixed,
  150. maybe avoid Unix Timestamp. When prompted pick any of the available date
  151. selection widgets, e.g popup calendar or the triple select list. You may tick
  152. the "Collect an End date" box too, if you wish. After you have configured on
  153. the block configuration page a global filter for the selected date field or
  154. range, the global filter will render itself using the same widget you picked for
  155. the field on the content type. However, the global filter will always appear as
  156. a date range. Filtering on a single date would be a little restrictive!
  157. Finally, as with any other global filter you need to hook it into your view as
  158. a contextual filter. Use either just the field start date or create a second
  159. contextual filter to also require the content's end date being inside the
  160. filter range. In either case scroll down the bottom of the contextual filter
  161. panel to the heading "Dates to compare". Press the button "Only this field".
  162. GLOBAL FILTER FOR SEARCH TERMS
  163. ==============================
  164. To configure a global filter as a global keyword search, select as the driver
  165. the pseudo-field "Search: Search terms". The widget will always be a text field
  166. regardless of which radio button you press.
  167. In your View, after pressing "Add" in the Contextual Filter tick the check box
  168. "Search: Search terms", followed as per usual by the "Provide default value"
  169. radio button. Select "Global filter (field or search terms)" from the drop-down.
  170. Press Apply at the bottom of the panel.
  171. If you have the Search API module enabled the process is the same.
  172. GLOBAL FILTER FOR RANGES
  173. ========================
  174. With the "Contextual Range Filter" module enabled and your contextual filter
  175. converted to a contextual range filter, you may use any of the following
  176. widgets to enter filter ranges as opposed to single filter values:
  177. o text field, enter ranges by separating "from" and "to" by a double hyphen,
  178. for example 0.5--2.5 or a--k or, if the field is a list, use either the keys,
  179. e.g., 3--7 or the list names, e.g. toddler--teenager
  180. o range, i.e. separate "from" and "to" text fields, no need to enter the
  181. separator
  182. o inherit range slider (requires the Slide with Style module from the project
  183. http://drupal.org/project/select_with_style)
  184. GLOBAL FILTER FOR PROXIMITY USING LOCATION MODULE
  185. =================================================
  186. If you have the Location module enabled you can globally filter content or user
  187. accounts based on a distance from a postcode or lat/lon pair of coordinates
  188. as entered by the visitor.
  189. If you wish to base proximity on a postcode the visitor enters, then make sure
  190. that you are connected to the Internet and have selected an appropriate web
  191. service on the Location configuration page
  192. admin/config/content/location/geocoding.
  193. When using the Google geocoding service entering a blank API key usually works.
  194. To configure the global filter block select as the driver the pseudo-field
  195. "Location module: Distance/Proximity". The widget in this case will be a single
  196. text field -- for an alternative option, see the next section.
  197. As far as the Contextual Filter in Views is concerned, tick "Provide default
  198. value" as per normal, then select "Global filter (proximity)" and enter a
  199. default distance. Scroll down the panel to select whether you want the user to
  200. enter a lat,long pair or a postcode in the global filter text field. Also select
  201. the unit (km or mile) and the shape of the proximity area (circular or
  202. rectangular). Press Apply at the bottom and you're done.
  203. The proximity filter presents itself as a textfield for the visitor to enter
  204. their postcode or lat/lon pair (separated by a comma). Visitors may optionally
  205. append a space or underscore and a distance. If the distance is omitted, then
  206. the default as set on the Views "Global filter (proximity)" configuration panel
  207. is taken.
  208. If you have "IP Geolocation Views and Maps" enabled then you can set as an
  209. initial default the postal code to that of the visitor's location upon first
  210. visit. To do this enter this code snippet as the global filter global default:
  211. $location = ip_geoloc_get_visitor_location();
  212. return $location['postal_code'];
  213. ?>
  214. GLOBAL FILTER FOR ADDRESS OR VISITOR'S LOCATION (GEOFIELD, LOCATION MODULES)
  215. ============================================================================
  216. To configure the global filter block for use with the Location module select as
  217. before as the driver the pseudo-field "Location module: Distance/Proximity".
  218. When using Geofield, select the name of the correct field from the drop-down.
  219. For the widget select "Proximity (reference location and distance)".
  220. The widget renders as a small form with two fields. The first is to specify a
  221. distance, in km or miles as configured on the Views contextual filter UI panel.
  222. The second field when left blank will default to the user's current position
  223. as retrieved by module IPGV&M (drupal.org/project/ip_geoloc), if enabled. If
  224. an address or approximate address, like "Melbourne, Australia" is entered, then
  225. the Google geocoding service will be used to obtain lat/lon. This requires the
  226. Geocoder module.
  227. GLOBAL FILTER FOR CITY, NOT USING LOCATION OR GEOFIELD MODULES
  228. ==============================================================
  229. Here are three examples. For an IP-based lookup of the visitor's location
  230. configure either Smart IP or GeoIP API. For an HTML5 (i.e GPS) location based
  231. approach also configure IPGV&M. We assume that you have already defined a
  232. field named "City" (field_city) on one or more of your content types. This
  233. field may be either a text field or taxonomy term reference.
  234. At /admin/structure/block find a block named "Global filter block # (not
  235. configured)". Press "configure".
  236. Enter in the "Block title" box.
  237. In the dropdown "Choose the field to be used as a global filter" find your
  238. city field: "Field: City (field_city)". Widget: "Inherit from field".
  239. Under "Alternatively specify a default through PHP code" enter a code snippet
  240. as per below.
  241. When using Smart IP, enter:
  242. When using GeoIP API enter:
  243. city; ?>
  244. Or when using IPGV&M:
  245. For the "Region setting" select "Content". Finally press "Show block only on the
  246. listed pages" and enter the path to your View. Click "Save block".
  247. Now go back to edit your View.
  248. In the "Advanced" fieldset on the right "Add" a Contextual Filter for "Content:
  249. City (field_city)". On the next panel press "Provide default value", then for
  250. the Type select "Global filter (field or search terms)". Click "Apply".
  251. Save the View.
  252. That should be it. Log out. Go to the URL associated with the View and it
  253. should be filtered by your city. You should also see a text box there to filter
  254. the View by any city you type. This should work for both logged-in and anonymous
  255. users. A further option is that if the same field_city is also added to the user
  256. profile at admin/config/people/accounts/fields, (e.g. "My favourite city"), then
  257. the value entered by the account holder on the "Edit account" page will become
  258. the initial value of the exposed filter.
  259. Note: this solution may not work when you're not connected to the Internet and
  260. your IP address is "localhost", 127.0.0.1.
  261. USEFUL VIEW OPTIONS
  262. ===================
  263. On the View edit page, in the contextual filter configuration panel, after you
  264. have selected a global filter to provide the default value, scroll down the
  265. panel and expand the More field-set for a couple of additional useful options.
  266. "Allow multiple values" is MANDATORY when you configured your global filter to
  267. render as a multi choice widget.
  268. "Exclude" is nice to populate a view with the compliment of the global filter
  269. selection (e.g. all countries except South American countries).
  270. ADVANCED OPTIONS: ROTATING BLOCK CONTENT
  271. ========================================
  272. A special auto-cycle filter is available under the "Advanced configuration"
  273. fieldset on the Configuration >> Global Filter page. You can use this to create
  274. block content that changes with every click on the site. Examples are ads, news
  275. items or user profile pictures, that have to follow a specific logical sequence,
  276. for instance chronological, alphabetical, by section or chapter number, or by
  277. vocabulary term order.
  278. You normally need two views for this (although at the bottom of this page we'll
  279. mention a short-cut alternative for the second view). Let's call these the
  280. filter view and the block/page view.
  281. The filter view simply needs to return in the desired order, the nodes (or
  282. users or etc.) that you wish to rotate through the block. This view does not
  283. need page or block displays and doesn't have to output any fields, as the nids
  284. are silently output anyway. However, to verify the view correctly returns the
  285. nodes in the order you wish them to cycle through the block, we suggest to
  286. configure the view format to output titles or teasers. Save this view.
  287. Activate this view as the driver for the auto-cycle filter at Configuration >>
  288. Global Filter, opening the "Advanced configuration" fieldset. Select the view
  289. you've just created and press "on every page load".
  290. The block/page view needs to produce at least as much content as the filter
  291. view. In fact you could start by cloning the filter view and use it as a base.
  292. Select any display format and any fields you like to display for the block of
  293. rotating content. Don't forget to add a block or page display to this view!
  294. Remember that only one of these pieces of content will be shown at any one time,
  295. as auto-selected by the above filter view. This is established by adding a
  296. Contextual Filter to the block/page view (Advanced fieldset, upper right
  297. corner). Tick "Content: Nid" and "Apply...". Press "Provide default value" and
  298. then select "Global filter (view)" from the Type drop-down. Your auto-cycle view
  299. should appear in the next drop-down. Press "Apply...". Save this view.
  300. Finally, if you went for a view with a block rather than page display at
  301. Structure >> Blocks, move your block from the Disabled section into the desired
  302. page region.
  303. Verify the view appears and note that with every new page you visit the
  304. page/block view displays another piece of content.
  305. Shortcut: if you're happy to have just the title show in the block, you could
  306. do the following. Don't create a second view. Create a block instead, select
  307. "PHP code" for the block text format and enter in the block body text area:
  308. $node = node_load(global_filter_get_session_value('view_autocycle'));
  309. print theme('node', array('elements' => array('#node' => $node, '#view_mode' => 'teaser')));
  310. ?>
  311. Depending on how your theme's node.tpl.php is organised this will most likely
  312. show just the hyperlinked title of the next piece of auto-selected content.