views:

82

answers:

1

Hi friends,

I'm starting my first Drupal project, pretty excited :) I have a question;

the project is a hotel directory site. at sidebar I have locations list (London, Manchester, Liverpool, etc..) and filter the hotels related on location click.

So, how should I create these cities? Should I put them manually and give links manually depending on location id? or is there any better way to create this location list and linking filtering dynamically (via cms, or custom module, etc...)

Appreciate advices!!!!

+3  A: 

This would be a good example of when to use the core (part of the base Drupal software) Taxonomy module. With Taxonomy you can set up one or more lists of terms that describe some or all of your nodes. For example, you can have a list of locations, a list of amenities (pool, sauna, golf course, etc.), and a list of price ranges (low, medium, high).

For each hotel you can select a location from the locations list, one or more amenities, and a price range. Then you can select all of the hotels that match one of the lists, using a neat feature of Taxonomy where it will return a list of those nodes.

The lists of terms are called "Vocabularies", and you'll want to create a vocabulary for each list. Go to Administer -> Taxonomy -> Add Vocabulary. Give it a name, like "Location" a description if you'd like, and choose the content types that it should be allowed to be associated with. (In your case, the hotels should probably be a custom content type that is different from the Page and Story types, but for trying this out, just pick Page for now.) There are several checkboxes at the bottom to decide on: Don't check Tags or Multiple Select, as these allow free tagging by users (images users making up city names) and also allow a node to have multiple locations. Do check the Required checkbox, as each hotel should have one.

Click Save and then click Add Terms on the vocabulary list page, and add a few locations. Then create a few hotel nodes (Pages for now) and you'll see that there is a new section in the Create Content page that is a dropdown selector that contains the locations. Choose one for each hotel, and add a few hotels in the locations that you just created.

To select the hotels for a given location, you will need to know the path associated with each term. Go back to the Taxonomy admin page and choose List Terms for the Location vocabulary. On the Terms in Location page you can get the list of hotels for a location by clicking on a location's name. The resulting page's path (e.g. example.com/taxonomy/term/2) would be what you'd use in your menu for that location. Each location will have its own term number that would be at the end of the path.

This is the simplest way to use the Taxonomy module, but it works really well with other modules like Views. Using Views you can control the format of the list of hotels for each location.

For more information, see the Taxonomy documentation and especially this sub-page called About Taxonomy.

flamingLogos
wowowo! thanks for such a detailed answer! I honestly appreciate your time! I just followed your steps and created sample location hotels, working great :) so is there any dynamic way to list this location at sidebar? or I create the list manually html based and paste to sidebar in theme, and giving links for term/1, term/2 etc...?
artmania
Have a look at the Views module, it has some pre-configured settings for displaying taxonomies.
lazysoundsystem
No problem--I remember what it was like to be new at Drupal. Like @lazysoundsystem said, take a look at the Views module (as well as CCK, Token, and Pathauto). They all work really well with Taxonomy and will allow you to do many things without resorting to hard-coding. That's the beauty of the Drupal modules: used properly, they are truly greater than the sum of their parts.
flamingLogos

related questions