Search code examples
drupaldrupal-taxonomy

Drupal 7: Creating a taxonomy filter using checkboxes


I'm looking to create a page with a taxonomy filter using checkboxes and when one or more checkboxes is ticked this creates the list of pages below that are tagged with the chosen taxonomy. E.g The filter may contain categories A, B, C, D and E as checkboxes. If the user ticks Category A and Category D then clicks a submit button all pages that are associated to A and D will be listed below.


Seem to be struggling using both methods! Has anyone got a tutorial or step by step guide I could use? Otherwise, can someone help with the following questions?

  1. I created the form in block--block--1.tpl.php by getting the taxonomy tags using taxonomy_get_tree(1); and looping through these to create the checkboxes. I was hoping I could then somehow get the post data and create a list of events (pages) which contain the tags selected. Where would I do the PHP for this? I'm guessing it wouldn't be within the template file so would it be in my custom module? If so, how?

  2. I was thinking of creating a form and using hook_form_FORM_ID_alter but how do I create the form using the taxonomy tags? How do I then add this form into my block?

  3. Any other options?

Thanks


Solution

  • You can do this using the excellent Views module. Views lets you create custom lists of content that you can set to be filtered by the user. There's a good article on building a filterable list with views here.

    http://www.advomatic.com/blogs/amanda-luker/build-filterable-staff-directory-drupal-6-or-7

    You should be able to easily adjust this tutorial to include checkboxes instead of drop downs.