Jump to content

Firm - City - Category Relation


Kemal
 Share

Recommended Posts

Hi, i have 3 template

Firm , Category, City

i can list Firms on the Category template- ex: construction firms list

$firms = $pages->find("template=firm, categories=$page");

i can list Firms on City template ex: atlanta firms list

$firms = $pages->find("template=firm, cities=$page");

but  what i want to do is

construction firms on atlanta

and

atlanta construction firms

i mean on category page i want to filter city

on city page i want to filter results according to category

i can do it by this way

$firms = $pages->find("template=firm, categories=$page");
 
foreach($pages->get("/cities/")->children() as $city) 
{
 
$categorycityfirm= $pages->find("template=firm, categories=$page, cities=$city");
 
}

On category template by this code above i get results. But what i want is there must be link of cities on cateory page and when i click on city name it should opens filtered result.

So should i implement new template like categorycityfirms and citycategoryfirms?

Page hierarchy 

Home

  Firms

     -firm1

     -firm2

  Cities

     - city1

     - city2

  Categories
     -cat1
     -cat2

 

Link to comment
Share on other sites

Are you familiar with $input->get? You can simply accept a city argument on category pages and vice versa. On your category page, you list cities like so:

foreach ($cities as $city)
{
    echo "<a href='{$city->url}?category={$page->id}'>{$city->title}</a>";
}

On the city page where that link leads, you accept the argument "category":

$category = $pages->get($input->get['category']);

Now you know the city and the category to search for.

Refer to the docs for more info on $input.

Note there are several other ways to solve your problem.

  • Like 1
Link to comment
Share on other sites

wow bulls eye,

its really what i was looking for. It solves my problem thank you very much Romero.

Is there a way to use ?category={$page->name} instead of ?category={$page->id} ?

 I am askng it for seo purposes but i dont know if its indexed by this way

Link to comment
Share on other sites

Sure, as long as the name is unique enough for you to put it in your selector. You may also want to look into urlSegments. For this purpose, they’re basically the same thing, but with prettier urls. For example the url might be /mycategory/atlanta/, where atlanta is a urlSegment. It doesn’t exist as a real page, but you can access it with $input->urlSegment1. Or something like that. I'm on mobile, so just check out the docs on urlSegments. It’s very easy to implement.

Just always make sure you only accept values you expect, and sanitize your stuff. In case of this example, you’d use $sanitizer->pageName().

Link to comment
Share on other sites

  • 3 weeks later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...