dxw / iguana-theme
v1.1.0
2023-08-14 14:52 UTC
Requires
- php: ^7.4||^8.1
- dxw/iguana: ^1.1
Requires (Dev)
- 10up/wp_mock: ^0.4.2
- dxw/php-cs-fixer-config: ^2.1
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.0
README
为基于iguana的模板提供辅助函数和模板布局。
\Dxw\Iguana\Theme\Helpers
辅助函数。
安装
将以下内容添加到 app/di.php
$registrar->addInstance(new \Dxw\Iguana\Theme\Helpers());
用法
您的类可以声明辅助函数
<?php
namespace Dxw\MyTheme;
class MyClass implements \Dxw\Iguana\Registerable
{
private $helpers;
public function __construct(\Dxw\Iguana\Theme\Helpers $helpers)
{
$this->helpers = $helpers;
}
public function register()
{
$this->helpers->registerFunction('myFunc', [$this, 'myFunc']);
}
public function myFunc($a)
{
echo esc_html($a + 1);
}
}
要从模板中调用此函数
<?php h()->myFunc(4) ?>
使用 h()
表示您只需将一个函数注入全局命名空间。而 h()
比输入完整命名空间要短得多。
您只需在实例化类时传递 Helpers
实例。示例
$registrar->addInstance(new \Dxw\MyTheme\MyClass(
$registrar->getInstance(\Dxw\Iguana\Theme\Helpers::class)
));
\Dxw\Iguana\Theme\Layout
和 \Dxw\Iguana\Theme\LayoutRegister
布局模板。
安装
将以下内容添加到 app/di.php
$registrar->addInstance(new \Dxw\Iguana\Theme\Helpers());
$registrar->addInstance(new \Dxw\Iguana\Theme\LayoutRegister(
$registrar->getInstance(\Dxw\Iguana\Theme\Helpers::class)
));
用法
将类似的内容添加到 layouts/main.php
(在您的主题目录中)
<!doctype html>
<html>
<head>
...
</head>
<body>
<?php h()->w_requested_template() ?>
</body>
</html>
并从所有模板中移除对 get_header()
/get_footer()
的调用。