[wordpress插件] Custom Post Type Template Redirect自定义帖子类型模板重定向

wordpress 插件 文章 2020-04-09 09:00 478 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

One of the shortcomings of Custom Post Types in WordPress is that there’s no way to easily set a different custom template from the standard single.php.

WordPress中“自定义帖子类型”的缺点之一是无法与标准single.php轻松设置不同的自定义模板。

If it’s a custom post type, it’s got custom information, and I want to put it in a custom template!

如果是自定义帖子类型,则其中包含自定义信息,我想将其放入自定义模板中!

So I threw together a plugin to handle this.

因此,我整理了一个插件来处理此问题。

With this plugin installed and activated, it checks your template directory for posttype.php then t_posttype.php.

安装并激活此插件后,它将检查模板目录中的posttype.php,然后是t_posttype.php。

If neither exists, then the standard WP template rules take effect.

如果两者都不存在,则标准WP模板规则将生效。

For example, if your custom post type is ‘books’, it’s going to check your template directory for ‘books.php’.

例如,如果您的自定义帖子类型为“ books”,它将在模板目录中检查“ books.php”。

If it finds it, it will use that as the template for your ‘books’ posts.

如果找到它,它将用作“书”帖的模板。

If not, it will check for ‘t_books.php’, and use that as the template for your ‘books’ posts.

如果不是,它将检查“ t_books.php”,并将其用作“ books”帖子的模板。

If it finds neither, the standard WP logic kicks into place, looking to see if you’ve defined a template for the post, and, if not, using single.php.

如果找不到,则标准WP逻辑开始生效,以查看是否已为帖子定义模板,如果没有,请使用single.php。

安装步骤

Simply install and activate this plugin, then start putting your templates for custom post types into your theme’s directory using the naming structure above.

只需安装并激活此插件,然后使用上面的命名结构将自定义帖子类型的模板开始放入主题目录中。

下载地址
https://downloads.wordpress.org/plugin/custom-post-type-template-redirect.zip
-EOF-

AI助手支持GPT4.0