Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have following situation:

My clients site displays various items respresented by posts. The menu allows two options to view these posts:

  • First is "show all items of type X"
  • Second is "show all items in location Y"

The challenge I currently face is, that the location-view should use a different layout than the type-view.

For example:

The posts are real estate items (house, lot, semi-detached, condo, ...) The locations are cities (vancouver, toronto, ...)

  • View 1: Show me all houses, done via url "site.com/category/houses"
  • View 2: Show me all items in Vancouver, via url "site.com/category/vancouver"

Currently both views work correctly, but the "vancouver" view should also include an map, which is not included in the first case.

So I need to find a way to determine the "mode" of the page (by location or by type) - my current approach is to test the URL, but this seems very very quick-n-dirty style.

What real solution can be used in these cases? I cannot simply use function "in_category()" since each post will have a category for type and location

share|improve this question
1  
Are your locations and types stored in two taxonomies? If so, your URLs don't seem correct, they should each be different (e.g. site.com/location/vancouver). Then you just create a different template file for each one - see the template hierarchy Codex page. –  Simon Blackbourn Apr 8 '13 at 14:41
    
Ahhh, that's a great idea! Until now I did use categories for this (each item was in category like "house" and "vancouver"). But actually you are right, this should be two distinct taxonomies. Problem solved –  Philipp Apr 8 '13 at 16:56
    
By the way, you can't use the word 'type' for custom taxonomies (it's one of WordPress' reserved terms), so you'll need to choose something else for that one. –  Simon Blackbourn Apr 8 '13 at 23:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.