Jump to content

How filters work in PW?


zilli
 Share

Recommended Posts

I need some help in understanding how filters work with PW pages and templates. 

I need to convert this HTML template to PW. Here is a working example. That specific page is giving me nightmares. 

What I think I know so far:

  • the front-end doesn't bother me, I have that covered 
  • each single hotel page has its features/facilities/characteristics 
  • those features/facilities/characteristics should be in the single-hotel template
  • a hotel index listing template should be created to hold an index of all the hotels(paginated)

Now, do I need a sidebar template to hold the PHP logic of the filter or is that part of the hotel index?

Link to comment
Share on other sites

There's really no difference between a 'filter' and a 'search'. The filter sidebar is a effectively a search form that submits automatically every time one of the form elements changes (the submit is executed with Javascript).

The index page is effectively a search results page - when no filters are set the search is fully open. Using a variable for your $pages->find() selector string it would be something like:

$selector = "template=hotel, limit=5";

In the index template you look for $input->get() variables. As an example, take a single GET variable: stars=4

You check that the variable name is valid (is one of the variable names you are expecting, otherwise ignore it). You sanitize the value appropriately for that variable (in this case it should be an integer). Then you add to your selector string accordingly, narrowing down the results your selector will return...

$selector .= ", $approved_var=$sanitized_value";

You will probably build up your selector string by looping over all of $input->get().

You don't need a separate template for the filter form. If you want to use the filter on several templates you can put the code in a separate PHP file and include it in your templates.

Check out the Skyscrapers profile for a good example of a search template:

https://github.com/ryancramerdesign/skyscrapers2/blob/master/search.php

https://github.com/ryancramerdesign/skyscrapers2/blob/master/_func.php

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...