ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Advanced Query with URL Segments

September 19, 2011 12:00pm

Subscribe [2]
  • #1 / Sep 19, 2011 12:00pm

    Andrew Fairlie

    126 posts

    Hi all,

    I’ve had a quick look at this but couldn’t find a solution that really fit my needs.

    Essentially I have a couple of channels: county, town, service, listing, person. The website should allow you to search a “IT Expert in Westminster, London” for example using the url

    http://acme.com/london/westminster/it-expert/

    My current thinking is that each of the URL segments would equate to the url_title of each entry for the channel (‘london’, ‘westminster’, ‘it-expert’).

    There is only to be one result for each of these terms, and it should load up the appropriate person once it has been found. For example,

    http://acme.com/london/westminster/it-expert/

    might load “Joe Bloggs”’ entry.

    The listing channel is a combination of many related entry fields for town, service and person.

    The ideal query would be (in very a pseudo way).

    Find the ‘listing’ entry where
    1) listing_service->url_title == segment_3
    2) listing_town->url_title == segment_2
    3) listing_town->town_county->url_title == segment_1

    However I can’t figure out for the life of me the best way to do this. I’ve considered the query module, search module and straight up PHP.

    It was also considered to ‘hard code’ these into a pages URL but this is prone to user error.

    Any guidance would be appreciated.

    Kind Regards,
    Andrew

  • #2 / Sep 19, 2011 10:32pm

    Dan Decker

    7338 posts

    Andrew,

    Hmmm… this is somewhat of an unusual use case for ExpressionEngine, in so far as you have described it. Let’s see if we can work out a better performing solution. Nesting channels as you describe might have adverse performance on a well traveled site.

    Firstly, in general, the fist 2 segments of an EE URL translate to a template-group and template. So, in your example, you would have a template group named ‘london’ and inside that would be a template named ‘westminster’ Following this example, you could then have templates identifying the other districts in London as well.

    Then let’s say you have a Channel called “People” or whatever you like. This will be the channel that stores the info about you various professionals. For this Channel you would create Categories that describe your areas of expertise, in this example “it-expert”.

    Using an add on like Low’s seg2cat you could craft your template like this:

    {exp:channel:entries
      channel='professional'
      limit='1'
      status='not closed'
      orderby='title'
      category='{segment_3_category_id]'
    }
    {title}
    {bio}
    etc…
    {/exp:channel:entries}


    So, your URLs would look like so: /london(template-group)/westminster(template)/it-expert(category)/

    Since this fall under a how-to/best practices area, I’m going to move this into Community Help to keep the discussion going.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases