geistpress / wp-helpers
v0.1.1
2017-08-24 09:56 UTC
Requires
- php: >=5.5
- mrubiosan/facade: ^1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 20:14:52 UTC
README
安装
$ composer require geistpress/wp-helpers
使用
初始化加载和视图辅助器并注册侧边栏
// Init WP-Helpers add_action('init', function () { // Init Loader $loader = new \GeistPress\Helpers\Foundation\Loader(); // Register all class in sidebars directory with the App\Sidebars namespace $loader->register(__DIR__ . '/resources/sidebars', 'App\Sidebars'); // Register only the Bar class and return its instance $foobar = $loader->register(\Foo\Bar::class); // Init Views \GeistPress\Helpers\Facades\View::init(__DIR__ . '/resources/views/'); });
可注册
要使用加载器注册类,该类需要实现 Registerable
接口并包含一个 register
方法
namespace App\Sidebars; use GeistPress\Helpers\Foundation\Registerable; class HeaderBar implements Registerable { /** * Register sidebar */ public function register() { register_sidebar([ 'name' => __('Header Bar', 'app'), 'id' => 'header-bar', 'description' => __('Top Bar above the navbar', 'app'), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', ]); } }
视图
// Render /resources/views/breadcrumbs.phtml and pass the variable $current='home' to it \GeistPress\Helpers\Facades\View::render('breadcrumbs', ['current' => 'home']);