WordPress会自行寻找使用哪个模板文件。如果你知道重写规则,你可以看看通过这些页面:
OR,这里有几个简单的解决方案:
使用分层页面
site.com/page1/sub-page/sub-page/
您必须使用浏览器通过/ wp-admin /添加页面,然后在其中设置其父页面。您也可以选择使用特定模板(PHP主题文件)(请参阅:Theme Development并向下滚动到自定义页面模板)。
采用分层分类
你也可以使用分层分类标签的帖子,然后列出它们的类别档案网页。例如:
您可以拥有site.com/category/brand/audi/(注意,您可以在wordpress设置中更改此网址的“类别”基本部分)。
您可以为各种标签归档页面创建模板文件:category-brand.php将为site.com/category/brand/
url加载,而category-audi.php将加载为site.com/category/brand/audi/
url。
注意:根据您的网站的动态需求,您可能需要跳过使用category- {tag} .php,以便它通过泛型category.php。在这种情况下,我相信上述两个网址都会使用通用类别。php(缺少更具体的模板文件 - Template Hierarchy向下滚动以查看模板层次结构图)。
这会阻止您必须为每个单独的标记创建单独的文件。使用get_query_var()方法获取特定类别标签。
最后但并非最不重要
如果仍然遭到拒绝,有另一种方式来切割的URL,而无需使用重写规则。 BuddyPress(一个WordPress插件)有一个功能,可以将url分成几块(/ 1/2/3 /),然后在PHP中使用它们。我不确定这是如何工作的,但如果你想看一下,你可以谷歌/下载BuddyPress,并查看buddypress/bp-core/bp-core-catchuri.php
文件。
这里的文档块:
/**
* Analyzes the URI structure and breaks it down into parts for use in code.
* BuddyPress can use complete custom friendly URI's without the user having to
* add new re-write rules. Custom components are able to use their own custom
* URI structures with very little work.
*
* @package BuddyPress Core
* @since BuddyPress (1.0)
*
* The URI's are broken down as follows:
* - http:// domain.com/members/andy/[current_component]/[current_action]/[action_variables]/[action_variables]/...
* - OUTSIDE ROOT: http:// domain.com/sites/buddypress/members/andy/[current_component]/[current_action]/[action_variables]/[action_variables]/...
*
* Example:
* - http://domain.com/members/andy/profile/edit/group/5/
* - $bp->current_component: string 'xprofile'
* - $bp->current_action: string 'edit'
* - $bp->action_variables: array ['group', 5]
*
*/
function bp_core_set_uri_globals() {
这个插件已经由我和它没有运气:(你有任何其他的想法或其他建议,请我需要它快:)? –