victorhugobatista/wp-eruptor

以更少的设置扩展您的单页,就像水中的熔岩一样

0.3.0-beta 2018-11-18 14:15 UTC

This package is auto-updated.

Last update: 2024-09-19 09:29:18 UTC


README

以更少的设置扩展您的单页,就像水中的熔岩一样

screenshot

简单用法

使用以下命令通过composer添加库

composer require victorhugobatista/wp-eruptor

将以下代码添加到您的函数中。模板文件将默认在active-theme-dir/single-page-children中加载。

use victorhugobatista\WpEruptor\Eruptor;
Eruptor::initialize();

您可以传递模板将被加载的根目录,如下所示

use victorhugobatista\WpEruptor\Eruptor;

$themePath = get_template_directory();
$templateToInclude = "{$themePath}/my-custom-template-dir";

Eruptor::initialize($templateToInclude);

模板文件

放置模板的文件结构必须如下所示

  • 模板根目录(目前,模板文件夹必须放在这里
    • single-page-children(目前,此名称不能更改
      • single-book(这代表单页模板文件的名称,例如single-book.php
        • child-a.php(/book/existing-post-name/child-a
        • child-b.php(/book/existing-post-name/child-b
        • child-c.php(/book/existing-post-name/child-c
      • single-movie
        • child-d.php(/movie/existing-post-name/child-d
        • child-e.php(/movie/existing-post-name/child-e
        • child-f.php(/movie/existing-post-name/child-f

父单页帖子的ID将在模板中作为

<?php echo $pageData['post-id'] ?>

挂钩参考

eruptor/data*钩子的示例

/!\通配符*可以替换为上述eruptor/data过滤中的任何一项/!\

add_filter('eruptor/data*', function($data) {
  return array_merge($data, [
    'new-data' => 'new data added to template',
  ]);
});

新数据将在模板上的$pageData数组中可用

<?php echo $pageData['new-data'] ?>

下一步(从代码中添加的@todo注释)

  • 接收需要添加到主类路由上的帖子类型。
  • 添加过滤器,允许通过帖子类型、帖子名称和模板名称修改标题、内容和页脚。