I'm working on a website that includes a section for Barbers, and I want to achieve the following URL structure:
Barbers {domain.com/barbers This page will have 2 section, 1 section will list Barber Organizations and another section will have list of states which have barbers}/
├── Individual Organization Page {domain.com/<<organization-name>> this page will display overview of the organization, contact details and have further 3 parts}/
│ ├── Branches {domain.com/<<organization-name>>/branches this page will again display list of states related to the selected organization}/
│ │ └── Individual State {domain.com/<<organization-name>>/branches/<<state>> this page will again display list of cities, in the states selected previously, related to the selected organization}/
│ │ └── Individual City {domain.com/<<organization-name>>/branches/<<state>>/<<city>> this page will again display all branches, in the city selected previously, related to the selected organization}
│ ├── Barbers related to the selected organization {domain.com/<<company-name>>/barbers} this will again list all the states which have barbers related to the selected organization/
│ │ └── Individual State {domain.com/<<organization-name>>/barbers/<<state>> this page will again display list of cities, in the state selected previously, related to the selected organization}/
│ │ └── Individual City {domain.com/<<organization-name>>/barbers/<<state>>/<<city>> this page will again display all barbers, in the city selected previously, related to the selected organization}
│ └── Super Barbers related to the selected company {domain.com/<<organization-name>>/super-barbers this will display list of Super Barbers for the selected organization}
└── Individual State {domain.com/barbers/<<state>> this will display list of cities which have barbers, irrespective of any organization}/
└── Individual City {domain.com/barbers/<<state>>/<<city>> this will display list of barbers in the selected City, irrespective of any organization}
Please refer this image link for a flow chart for better understand and visualization.
I plan to create custom post types for the elements mentioned above and link them using ACF Relationship fields or the P2P plugin.
- Barbers
- Organizations
- States
- Cities
- Super Barbers
- Branches
Here are my questions:
- What templates do I need to create to achieve this URL structure?
- Is there a way to register a layout type based on the URL structure?
- How efficient and SEO-friendly can this approach be?
Please note that, apart from organizations, nothing else will have a single.php template; everything else will be in archive or listing format related to the parameters mentioned.
Thank you in advance.
Response: See URL Structure and Templates below.
Response: See Layout based on URL structure below.
Response: see my Comments
URL Structure and Templates
If I've understood the hierarchy correctly, I see the need for only two templates:
These templates would act like search results pages.
This is based on these assumptions:
1. The Branch entity has these attributes (among others):
2. The Barber entity has these attributes (among others):
3. Super-Barber is just a type of Barber and does not require its own search results page.
Further explanations are below.
WP_Rewrite
You will likely have to get familiar with WP_Rewrite to use your proposed URL structure. Examples below demonstrate when it would be used.
query_vars filter hook
The query_vars filter hook is needed to add custom URL query variables like
organization
,company
,state
, andcity
to WP_Query for use in page templates that act like search result pages.URL Structure for Branches
Individual Organization Page
The WordPress Post name permalink structure parses URLs starting with the first part of the URL Path and checks to see if it matches a Page, Category, or Post (in that order).
The Individual Organization Page URL structure (
domain.com/<<organization-name>>
) fits perfectly with WordPress default behavior. If Organizations are represented as Pages inwp_posts
, thepost_name
(slug) would be the<<organization-name>>
. Rewriting the URL with WP_Rewrite is unnecessary in this case.Branches
Looking at the URL for Branches (
domain.com/<<organization-name>>/branches
), it suggests a target page that shows Branches. However, your URL structure indicates that this URL targets a search results page. This page is a list of States where each State is associated with one or more Branches. It is as if a search page were used to filter a collection of Branches by Organization and only display a list of unique States.Given the URL structure (
domain.com/<<organization-name>>/branches
), WP_Rewrite could be used to convert:into something like:
The
branch-search
page would be an actual WordPress page withbranch-search
as thepost_name
. It would use a Custom Page Template (the page template for Branches) to recognize that since the only search key is the custom URL query variableorganization
, the results page should display a list of States.Individual State
Each State in the list on page
domain.com/<<organization-name>>/branches
would use a URL with the Individual State structure like this:domain.com/<<organization-name>>/branches/<<state>>
WP_Rewrite would convert:
into something like:
The
branch-search
page would recognize that since two search keys are used (organization
andstate
), the results page should display a list of Cities.Individual City
WP_Rewrite would convert:
into something like:
The
branch-search
page would recognize that since three search keys are used (organization
,state
, andcity
), the results page should list the related Branches.URL Structure for Barbers
Following the examples for URL Structure for Branches above, the URL structure for Barbers would use WP_Rewrite to convert URLs into those that target a Barbers page that uses the Barbers custom page template.
Individual State
Each State in the list would use a URL with the Individual State structure like this:
domain.com/barbers/<<state>>
WP_Rewrite would convert:
into something like:
The
barber-search
page would recognize that since one search key is used (state
), the results page should display a list of Cities.Individual City
WP_Rewrite would convert:
into something like:
The
barber-search
page would recognize that since two search keys are used (state
, andcity
), the results page should list the related Barbers.Other URL Structures
The remaining URL structures would be handled just as the examples above for URL Structure for Branches.
For example, Barbers related to the selected organization {
domain.com/<<company-name>>/barbers
} would have the URL converted into something like:domain.com/?pagename=barber-search&company=<<company-name>>
Layout based on URL structure
If you are asking if you can add custom WordPress Post Formats, the answer is no. According to WordPress:
However, if two page templates (one for Branches, one for Barbers) were used, multiple layouts could be coded within each template.
For example, the custom page template used for the
branch-search
page could use a different layout based on the number and type of search keys:And for the custom page template used for the
barber-search
page:If some layouts for Super-Barbers and Barbers are the same and some are different, Switch-Statements rather than If-Statements could be used to group the use of similar layouts. Otherwise, perhaps a strategy design pattern or "Layout" class could be used.