Jump to content

Show pages which "fieldset-x" is equal to "fildset-y" of the current page


luckybusted
 Share

Recommended Posts

Hey guys its me again,

I'm looking for a solution to show a List of Pages that have the same value in "fieldset-x" as the current Pages "title" e.g. .

My hardcoded Solution looks like this:

<?php
            
                $homepage = $pages->get("/stores/");
                $stores = $homepage->children("location_category=1065, city=1010");
                $children = $stores->getRandom(2);
            
                foreach($children as $child){
                ... echo ...
                }
            ?>
 


Now I need to check the title of the current page "{$page->title}" and check if it is equal to the value of fieldset "city" of a child Page of "Stores" ...

Any ideas?

Link to comment
Share on other sites

Let's see if I understood you right. "1010" does not look like a title, but more like an id, so I'm assuming you've got a structure like this:

/cities/
    /munich/
    /berlin/
/stores/
    /store-1/
    /store-7/
    /store-12/
    /store-17/
    /store-22/
Every store-nn page is using template "store" which has a Page field called "city", allowing you to choose a city for this store. Now if this was the structure and you were on page /berlin/, you'd like to find two random children of /stores/ where you've chosen "city" to be Berlin. This should do it (not tested though):
 
$children = $pages->find("parent=/stores/, city=$page, location_category=1065, sort=random, limit=2");
foreach($children as $child) {
    // ...
}
And if "city" really was a text field but otherwise I got your intentions about right, you only need to change "city=$page" to "city=$page->title" in the selector.

Probably this isn't exactly what you're after, but hopefully it helps you to get there. :)

  • Like 2
Link to comment
Share on other sites

Hey Guys,

thank you for your replies but my Problem is a bit more complicated.

My structure is like this:

/stores/
   /store-1/
   /store-12/
   /store-13/
   ...

/cities/
   /berlin/
   /munich/
   /cologne/
   ...

/store-category-1/
   /berlin/
   /munich/
   /cologne/
   ...

/store-category-2/
   /berlin/
   /munich/
   /cologne/
   ...

Maybe it seems stupid but my thoughts behind this where: I need a domain structure like ".../store-category/berlin/..."
So the Idea was to take the children of "cities" for filtering the stores and the city pages under the Store-Categorys just to show the results.

I hope you understand my Problem now a little better.

Link to comment
Share on other sites

Not a direct answer to your question but this seems like a really inefficient structure you got there. You could do something like this instead.

/stores/
   /store-1/
   /store-12/
   /store-13/

/cities/
   /berlin/
   /munich/
   /cologne/

/categories/
   /cat1/
   /cat2/
   /cat3/

and then enable URL segments on the category template, allowing for further filtering by city. So it works like:

/categories/cat1/ ---> show all store that have this cat.
/categories/cat1/berlin ---> show all stores that have cat1 and are located in berlin

In this case berlin would be urlsegment1 (not an actual page). If you don't know already some info is to be found for example in this thread.

In your case, a store can probably only be in 1 city, so you could even further structure it like:

cities
-city
--store
  • Like 3
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...