WordPress中自定义URL结构的自定义模板

yuvru6vn  于 2023-11-17  发布在  WordPress
关注(0)|答案(1)|浏览(153)

我在一个网站上工作,其中包括一个部分理发师,我想实现以下URL结构:

  1. 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}/
  2. ├── Individual Organization Page {domain.com/<<organization-name>> this page will display overview of the organization, contact details and have further 3 parts}/
  3. ├── Branches {domain.com/<<organization-name>>/branches this page will again display list of states related to the selected organization}/
  4. └── 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}/
  5. └── 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}
  6. ├── 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/
  7. └── 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}/
  8. └── 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}
  9. └── Super Barbers related to the selected company {domain.com/<<organization-name>>/super-barbers this will display list of Super Barbers for the selected organization}
  10. └── Individual State {domain.com/barbers/<<state>> this will display list of cities which have barbers, irrespective of any organization}/
  11. └── Individual City {domain.com/barbers/<<state>>/<<city>> this will display list of barbers in the selected City, irrespective of any organization}

字符串
请参阅此图像link的流程图,以便更好地理解和可视化。
我计划为上面提到的元素创建自定义文章类型,并使用ACF关系字段或P2P插件链接它们。
1.理发师
1.组织
1.国
1.城市
1.超级理发师
1.分支
以下是我的问题:
1.我需要创建哪些模板来实现此URL结构?
1.有没有一种方法可以根据URL结构注册布局类型?
1.这种方法的效率和SEO友好程度如何?
请注意,除了组织,没有其他东西会有一个单一的. php模板;其他一切都将在存档或列表格式相关的参数提到。
先谢谢你了。

mw3dktmi

mw3dktmi1#

我需要创建哪些模板来实现此URL结构?
响应:请参阅下面的URL结构和模板
有没有一种方法可以根据URL结构注册布局类型?
响应:参见下面的基于URL结构的布局
这种方法的效率和SEO友好程度如何?
回复:查看我的评论

URL结构和模板

如果我正确理解了层次结构,我认为只需要两个模板:
1.分支的页面模板,
1.理发师的页面模板
这些模板将充当搜索结果页面。
这是基于这些假设:
1.分支实体具有以下属性:

  • 组织
  • 状态

2.Barber实体具有以下属性(以及其他属性):

  • 组织
  • 状态
  • 超级理发师身份

3.超级理发师只是理发师的一种类型,不需要自己的搜索结果页面。
进一步的解释如下。

WP_Rewrite

您可能需要熟悉WP_Rewrite才能使用您建议的URL结构。下面的示例演示了何时使用它。

query_vars过滤钩子

需要query_vars过滤器钩子来添加自定义URL查询变量,如organizationcompanystatecity到WP_Query,以用于类似搜索结果页面的页面模板。

分支URL结构

单个组织页面

WordPress Post name permalink结构解析从URL路径的第一部分开始的URL,并检查它是否匹配页面,类别或帖子(in that order)。
单个组织页面URL结构(domain.com/<<organization-name>>)完全符合WordPress的默认行为。如果组织在wp_posts中表示为页面,则post_name(slug)将是<<organization-name>>。在这种情况下,无需使用WP_Rewrite重写URL。

分支

查看分支的URL(domain.com/<<organization-name>>/branches),它建议显示分支的目标页。但是,您的URL结构指示此URL针对搜索结果页。此页是状态列表,其中每个状态与一个或多个分支关联。就像使用搜索页按组织筛选分支集合,并且仅显示唯一状态列表一样。
给定的URL结构(domain.com/<<organization-name>>/branches),WP_Rewrite可用于转换:

  1. domain.com/<<organization-name>>/branches

字符串
变成这样的东西:

  1. domain.com/?pagename=branch-search&organization=<<organiztion-name>>


branch-search页面将是一个实际的WordPress页面,branch-search作为post_name。它将使用自定义页面模板(用于分支的页面模板)来识别,因为唯一的搜索关键字是自定义URL查询变量organization,结果页面应该显示状态列表。

单个状态

页面domain.com/<<organization-name>>/branches上列表中的每个State都将使用一个具有如下Individual State结构的URL:domain.com/<<organization-name>>/branches/<<state>>
WP_Rewrite将转换:

  1. domain.com/<<organization-name>>/branches/<<state>>


变成这样的东西:

  1. domain.com/?pagename=branch-search&organization=<<organiztion-name>>&state=<<state>>


branch-search页面将识别出由于使用了两个搜索关键字(organizationstate),结果页面应该显示城市列表。

单个城市

WP_Rewrite将转换:

  1. domain.com/<<organization-name>>/branches/<<state>>/<<city>>


变成这样的东西:

  1. domain.com/?pagename=branch-search&organization=<<organiztion-name>>&state=<<state>>&city=<<city>>


branch-search页面将识别出由于使用了三个搜索关键字(organizationstatecity),结果页面应该列出相关的分支。

理发师URL结构

按照上面分支的URL结构的示例,理发师的URL结构将使用WP_Rewrite将URL转换为针对使用理发师自定义页面模板的理发师页面的URL。

单个状态

列表中的每个State都将使用一个带有Individual State结构的URL,如:domain.com/barbers/<<state>>
WP_Rewrite将转换:

  1. domain.com/barbers/<<state>>


变成这样的东西:

  1. domain.com/?pagename=barber-search&state=<<state>>


barber-search页面将识别出由于使用了一个搜索关键字(state),结果页面应该显示城市列表。

单个城市

WP_Rewrite将转换:

  1. domain.com/barbers/<<state>>/<<city>>


变成这样的东西:

  1. domain.com/?pagename=barber-search&state=<<state>>&city=<<city>>


barber-search页面将识别出由于使用了两个搜索关键字(statecity),因此结果页面应该列出相关的理发师。

其他URL结构

其余的URL结构将按照上面的分支的URL结构的示例进行处理。
例如,* 与所选组织相关的理发师 * {domain.com/<<company-name>>/barbers}的URL将转换为类似于domain.com/?pagename=barber-search&company=<<company-name>>的内容

基于URL结构的布局

如果你问是否可以添加自定义WordPress Post Formats,答案是否定的。
新格式不能通过主题甚至插件引入。
但是,如果使用两个页面模板(一个用于分支,一个用于理发师),则可以在每个模板中编码多个布局。
例如,用于branch-search页面的自定义页面模板可以根据搜索关键字的数量和类型使用不同的布局:

  1. If ( organization AND state AND city ) Then
  2. Use branch layout
  3. Elseif ( organization AND state ) Then
  4. Use branch city layout
  5. Elseif ( organization ) Then
  6. Use branch state layout
  7. Else
  8. Use some other layout
  9. EndIf


对于用于barber-search页面的自定义页面模板:

  1. If ( ( organization OR company ) AND state AND city ) Then
  2. Use barber layout
  3. Elseif ( ( organization OR company ) AND state ) Then
  4. Use barber city layout
  5. Elseif ( organization OR company ) Then
  6. Use barber state layout
  7. Else
  8. Use some other layout
  9. EndIf

如果Super-Barbers和Barbers的布局有些相同,有些不同,则可以使用Switch-Statements而不是If-Statements来对类似布局的使用进行分组。否则,可能会使用strategy design pattern或“Layout”类。

展开查看全部

相关问题