suomato/luna

Base Camp 主题的命令行界面

v1.3.0 2018-07-27 11:09 UTC

This package is auto-updated.

Last update: 2024-09-12 11:13:00 UTC


README

Base Camp 主题的命令行界面。

命令

创建自定义文章类型

此命令可以帮助您快速创建新的自定义文章类型。

php luna make:custom-post-type {name}

参数为单数形式。如果名词有非标准复数形式(单数+s),可以通过复数选项定义例外,例如。

php luna make:custom-post-type person --plural=people

新文件创建在 /app/config/wp/custom-post-types/{name}.php

创建自定义分类法

此命令可以帮助您快速创建新的自定义分类法。

php luna make:custom-taxonomy {name}

参数为单数形式。如果名词有非标准复数形式(单数+s),可以通过复数选项定义例外,例如。

php luna make:custom-taxonomy country --plural=countries

新文件创建在 /app/config/wp/custom-taxonomies/{name}.php

创建路由

此命令可以帮助您以更清晰、更快速的方式为 WordPress API 创建新的路由。

php luna make:route {name}

新文件创建在 /app/config/wp/routes/{name}.php。创建的文件包含良好的文档模板。

创建简码

此命令可以帮助您创建具有非常干净模板的新简码。

php luna make:shortcode {name}

新文件创建在 /app/config/wp/shortcodes/{name}.php

示例

运行命令

php luna make:shortcode LuckyNumber

然后定义一些数据

    /**
     * @var string Shortcode name
     */
    protected $shortcode = 'lucky_number';

    /**
     * @var array|string An associative array of attributes
     */
    protected $attributes = [
        'number' => 7,
    ];

    /**
     * Return template of shortcode
     *
     * @param $attr An associative array of attributes
     * @param $content Enclosed content
     *
     * @return mixed
     */
    protected function template($attr, $content)
    {
        return 'This is my lucky number: ' . $attr['number'];
    }

现在简码 [lucky_number] 生成 这是我的幸运数字:7[lucky_number number="13"] 生成 这是我的幸运数字:13

还可以使用 Timber 的功能。在模板函数中,您可以使用如下方式返回 Timber 视图而不是字符串

// resources/views/shortcodes/lucky-number.twig

<p>This is my lucky number: {{ number }}</p>

******************************************************************

// app/config/wp/shortcodes/LuckyNumber.php

protected function template($attr, $content)
{
    return \Timber::compile('shortcodes/lucky-number.twig', $attr);
}

创建菜单页面

此命令可以帮助您创建新的菜单页面或子菜单页面以添加到 wp-admin 导航。

php luna make:menu-page {name}

此命令将在 /app/config/wp/menu-pages/{name}.php 中创建新的 MenuPage 类。生成的文件将包含菜单页面的属性。子菜单页面可以通过

php luna make:menu-page {name} --submenu

将生成新的 SubMenuPage 类在 /app/config/wp/submenu-pages/{name}.php