livy/plumbing-templates
Composer 安装命令:
composer require livy/plumbing-templates
包简介
Put your page (or custom post type) templates in better directories. Works with Sage!
README 文档
README
This tool gives you a way to improve the file organization of your custom page templates. For Wordpress 4.7+ you can also use templates for other post types.
It provides reasonable defaults that should work in most situations, but is also heavily configurable. Ships with built-in support for Sage 10. If you'd like to add built-in support for other frameworks with non-standard template organization, please file a PR or issue.
Usage
First, install the package:
composer require livy/plumbing-templates
Then call the tool like this, somewhere where it'll be run early (i.e. functions.php):
Livy\Plumbing\Templates\register_template_directory('custom-templates');
By default, the package assumes you're changing the template for the page post type, but you can specify any post type by passing a second parameter:
// Define templates for the `event` post type: Livy\Plumbing\Templates\register_template_directory('event-templates', 'event');
Usually, you'll want to wrap this in an action call to make sure it runs early enough, i.e.:
add_action('init', function () { Livy\Plumbing\Templates\register_template_directory('event-templates', 'event'); });
Advanced Usage
This package has a number of other options that allow you to customize its behavior. You can use the project's filters to do this, but it may be easier to pass your arguments all at once. To do this, use setup_template_location() instead of register_template_directory():
Livy\Plumbing\Templates\setup_template_location([ 'paths' => [ 'event-templates' ], 'post_type' => 'event', ]);
...will have the same effect as the example above.
The keys
pathsandpost_typemust be defined, or nothing will happen.
Options
The following is a list of all the options this package understands.
pathsarray - An array of paths (relative to your template root) to search for templates. Default: empty array.post_typestring - The post type to use these templates for. Default:page.filenamestring - Matched against filenames when searching for templates. Can be a string, simple glob (i.e.*.ext) or a regular expression. Default:*.php.template_rootstring - The template root, which is the directory that all template paths are relative to. It is unlikely you'll need to modify this value. Default: output ofget_stylesheet_directory().parent_template_rootstring - Same astemplate_root, but for templates in a potential parent theme. Ignored if there is no parent theme. It is unlikely you'll need to modify this value. Default: Output ofget_template_directory().containsstring - A string templates must contain. Can also be a regular expression. Used to identify what files are templates. Default:Template Name:.name_regexstring - A regular expression to get the name of a template from its contents. Default:/Template Name: ?(.+)/.post_type_regexstring - A regular expression to determine if a template applies to a particular post type.%post_type%will be replaced with the value ofpost_typeoption at runtime. Default:/Template Post Type:.*%post_type%(?=(?:,|$))/m.
Acorn and Sage
If you use the v10+ of the Sage starter theme or are using Acorn in some other capacity, you know that your templates are stored in a slightly non-standard location. Fortunately this package helpfully alters the defaults if it detects that you're using Acorn.
livy/plumbing-templates 适用场景与选型建议
livy/plumbing-templates 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.46k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2018 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 livy/plumbing-templates 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 livy/plumbing-templates 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-14