Questions tagged «template-redirect»

2
如何创建自定义URL路由?
我有一个非常特殊的要求,希望我能在不引起混淆的情况下解释它。我创建了一个页面模板,其中列出了从外部XML文件中获得的一些属性,到目前为止,没有问题,可以说URL如下所示: http://www.example.com/properties/ 每个属性都有一个链接,该链接应将用户重定向到“单个属性”页面,该页面显示有关该属性的更多信息。我想知道是否有一种方法可以使链接如下所示: http://www.example.com/properties/123 123该属性的ID 在哪里。因此,如果我有这样的URL,则properties/some_id希望能够加载视图文件(例如single.php或page.php文件),但特定于此URL条件。 这可能吗?

6
单个-{$ post_type}-{slug} .php用于自定义帖子类型
我最喜欢的Wordpress 模板层次结构部分是能够快速地为页面创建模板文件,而无需在Wordpress中编辑页面以选择模板。 我们目前可以这样做: 页面-{slug} .php 但我希望能够做到这一点: single- {post_type}-{slug} .php 这样,例如,在名为的帖子类型中review,我可以为位于以下位置的名为“我的伟大评论”的帖子制作模板single-review-my-great-review.php 有人设置过吗? single-{post_type}-{slug}.php

1
自定义帖子类型和template_redirect
我有两种自定义帖子类型(例如post_type_1和post_type_2),我想将其重定向到独立模板(single-post_type_1.php和single-post_type_2.php)来处理它们的显示。我不想将显示模板放在主题文件夹中,因为我希望它们独立包含在各自的插件文件夹中。 如何让他们每个人注册一个template_redirect钩子而不影响另一个?还是我应该使用其他技术? 当前,我正在插件1中进行此操作: add_action( 'template_redirect', 'template_redirect_1' ); function template_redirect_1() { global $wp_query; global $wp; if ( $wp_query->query_vars['post_type'] === 'post_type_1' ) { if ( have_posts() ) { include( PATH_TO_PLUGIN_1 . '/views/single-post_type_1.php' ); die(); } else { $wp_query->is_404 = true; } } } 而在插件2中: add_action( 'template_redirect', 'template_redirect_2' ); function template_redirect_2() { global …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.