Jump to content
Sign in to follow this  
luckybusted

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

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?

Share this post


Link to post
Share on other sites

if $page->title == $child->city ?

Or is this to obvious that I misunderstood your question?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you sinnut!

My structure was really crapy. Got it fixed allready.

But thank you guys anyway!

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snck
      Hi there,
      I have a problem constructing a selector that finds all pages that refer to pages with a specific template.
      I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.
      What I tried:
      $events = $pages->find("template=event, related_pages.template.name=exhibition"); Unfortunately it does not work (0 results).
      Same with this:
      $events = $pages->find("template=event, related_pages=[template.name=exhibition]"); At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:
      $events = $pages->find("template=event"); foreach($events as $event){ if(!count($event->related_pages->find("template=exhibition"))){ $events->remove($event); } }  
      I really hope that one of you can help me out.
      Thanks in advance!
      Flo
    • By Bacelo
      Hi there,
      I have a bit of trouble on filtering correctly some event pages by some selectors...
      I do have the following 2 date fields:
      - start date (fieldname = date)
      - end date (fieldname = enddate)

      Some events are a single day event (only start date) - some are a multi day event (end date).
      Past single day events should not show up.
      Current multi day events should show up (even if start day is in the past, but end date is future).
      So I have the following selector:
      if ($standort == '') { $termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)"); } else { $termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10"); } This selector
      $termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)"); works fine, but the follwing does not work (all past entries are also shown):
      $termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10"); I have no clue what I'm missing - any ideas?
    • By Kiwi Chris
      The selector in the following code included in a template is returning nothing, however if I take out the compId.resultsdate<={$today} bit, it works fine, although obviously not filtered on the date field.
      $today = strtotime(date('Y-m-d')); $setImages = $pages->find("template=competitionImage, compId={$page->id}, compId.resultsdate<={$today}, compSubject.name=s, imageRating.title=Merit|Honours,check_access=0"); Here's the results of an example from Tracey Debugger
      templates_id=79, resultsdate<=1587729600, status<2048   SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_resultsdate AS field_resultsdate ON field_resultsdate.pages_id=pages.id AND (((field_resultsdate.data<='2020-04-25 00:00:00' ) )) WHERE (pages.templates_id=79) AND (pages.status<2048) GROUP BY pages.id Over in my ready.php I have inside a hook that refers directly to the page template that's used for the pages in the page field above:
      $today = strtotime(date('Y-m-d')) $event->return = $event->pages->find("template=competition,eventEnd>={$today},eventStart<={$today}"); In this case the filtering on date fields (albeit different ones) works fine. Can anyone suggest why the filter on the date subfield of the page field isn't working?
      Just to confirm, I do have a date value in the field, and it is a date before today. 🙂
      The problem may be something blatantly obvious, but I can't for the life of me figure out why the selector is returning no results when I include the date filter.
    • By michelangelo
      Hello there,
      I am building my website, which has a dozen projects with 10 images each. Basically, I need a filtering system but built in the most efficient and user-friendly way. You can see below that the images flow sideways so being hidden, JS lazy loading was a good tool, but I just wanted to try AJAX. Is it fit for this purpose or it's more for dynamic content?
       

    • By Roberts R
      I have simple page structure:
      category subcategory simple-product simple-product simple-product simple-product subcategory .... category2 so Im at category page and running
      $pages->find("template=simple-product, has_parent=$page, limit=8"); and it returns 0 pages
       
      but this returns 4 pages
      $pages->find("template=simple-product, has_parent=$page"); Can someone explain why limit does not work here?
      EDIT:
      So I did some tests and it seems that any limit=n where n is >= actual page count that is possible ... selector return 0 results.
×
×
  • Create New...