承接 codebjorn/loki 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codebjorn/loki

Composer 安装命令:

composer require codebjorn/loki

包简介

WP Theme Loki

README 文档

README

Loki, WordPress Theme Boilerplate

GitHub release Generic badge

Loki is WordPress Theme Boilerplate using as a base Mjolnir Framework

If you think this approach is not working, please open an issue and let's discuss :)

Pre-Requirements

Before we proceed further, I suggest you to read documentation for:

  1. Mjolnir Framework.
  2. Laravel Blade
  3. Laravel Mix

Requirements

Requirements for this boilerplate are:

  • PHP 7.1+
  • Composer

Installation

You can install framework via composer:

composer create-project codebjorn/loki

Structure

Structure of boilerplate is:

|-- app                   // Folder where is stored all Facades,Services,Providers
|   |--Facades            // Folder that stores all facades used to get utilities & services from container
|   |--Providers          // Folder that stores all your providers
|   |--App.php            // Container file
|   |--Helpers.php        // File that store all functions need it for project
|-- assets                // Folder where all builded assets are stored
|-- blocks                // Folder where are stored all Gutenberg blocks
|   |-- <blockFolder>     // Folder with block
|       |-- components    // Folder where are stored all js components for Gutenberg
|       |-- data          // Folder where are stored json files such as attributes
|       |-- view          // Folder where is stored blade files for render
|       |-- index.jsx     // Block configuration file
|   |-- blocks.js         // File where is imported all blocks
|   |-- blocks.php        // File where are registered blocks using Block Facade
|-- config                // Folder where are stored configurations
|-- hooks                 // Folder where is stored all hooks
|   |-- actions.php       // File where are created new action hooks using Action Facade
|   |-- filters.php       // File where are created new filter hooks using Filter Facade
|-- resources             // Folder that stores all js,scss,views elements of theme
|   |-- js                // Folder for js of theme
|   |-- scss              // Folder for scss of theme
|   |-- views             // Folder for blade templates
|-- templates             // Folder where default wordpress templates are stored
|-- vendor                // Composer packages folder
|-- functions.php         // Default WP Functions.php 
|-- webpack.mix.js        //Laravel Mix configuration file

How all work

Add service into hook

  1. Create a new namespace in app folder and add new php service class
  2. Resolve this service using Service Provider in app/Providers folder, you can add it to AppServiceProvider.php or create a new provider and add it to config/app.php to load. More info about service providers
  3. After resolving a service you can inject it in another service or add it into hook in hooks folder, for example action hook:
Action::add('wp_enqueue_scripts', [\Namespace\Setup\Enqueues::class, 'front']);
Action::add('admin_enqueue_scripts', [\Namespace\Setup\Enqueues::class, 'admin']);

Work with WordPress templates

By default, all WordPress templates are stored in templates folder, you can change folder or disable this feature in config/theme.php.

To use templates and laravel blade engine we can use templates as kind of controller that will store all data that we need but render will make template engine, for example:

  1. Let's say we want to create/update template single.php, we create a new file templates/single.php
<?php

$post = \Mjolnir\Utils\Post::current();
$postTitle = $post->getTitle();
$postContent = $post->getContent();

\Loki\Facades\View::render('single', ['title' => $postTitle, 'content' => $postContent]);
  1. We create blade file in resources/views/single.blade.php
@extends('layout.app')

@section('content')
    <h1>{{$title}}</h1>
    {!! $content !!}
@endsection

Create Gutenberg Blocks

All blocks are stored in blocks folder. For creating a new block we will need:

  1. Create a folder inside blocks folder
  2. Create index.jsx in your new folder
import {__} from '@wordpress/i18n';
import {Fragment} from '@wordpress/element';
import Controls from "./components/controls";
import Editor from "./components/editor";
import Inspector from "./components/inspector";
import * as attributes from "./data/attributes.json";

const {registerBlockType} = wp.blocks;

export default registerBlockType('namespace/name', {
    title: __('Name', 'name'),
    attributes: attributes,
    edit: props => {
        return (
            <Fragment>
                <Controls {...props} />
                <Editor {...props} />
                <Inspector {...props} />
            </Fragment>
        );
    },
    save() {
        //gutenberg will save attributes we can use in server-side callback
        return null;
    },
});
  1. Create all components inside components folder:
  • controls.jsx - Toolbar of block
import {BlockControls} from '@wordpress/block-editor';

function Controls() {
    return (
        <BlockControls>
        </BlockControls>
    );
}

export default Controls;
  • editor.jsx - Main area of block
function Editor({attributes, setAttributes}) {
    console.log(attributes)
    return (
        <div className="name">
            <h1>Hello, {attributes.title}</h1>
        </div>
    );
}

export default Editor;
  • inspector.jsx - Sidebar panels
import {__} from '@wordpress/i18n';
import {InspectorControls} from '@wordpress/block-editor';
import {PanelBody, PanelRow} from '@wordpress/components';

function Inspector({attributes, setAttributes}) {
    return (
        <InspectorControls>
            <PanelBody title={__('Name')}>
                <PanelRow>

                </PanelRow>
            </PanelBody>
        </InspectorControls>
    );
}

export default Inspector;
  1. Create data folder and new attributes.json file:
{
  "classNames": {
    "default": "hero",
    "type": "string"
  },
  "title": {
    "default": "This is title",
    "type": "string"
  }
}

Also, you can use data folder to store and other json folder that can be used in you block.

  1. Create view folder where will be stored blade templates for your block, default one is block.blade.php:
<div class="{{$attributes->classNames}}">
 <h1>{{$attributes->title}}</h1>
 @include('hero.view.partials.element')
</div>
  1. Import you block in main blocks.js
  2. Add block in main blocks.php using block facade:
\Namespace\Facades\Block::add('namespace', 'name');

Testing

//TODO

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email quotesun@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

codebjorn/loki 适用场景与选型建议

codebjorn/loki 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 codebjorn/loki 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codebjorn/loki 我们能提供哪些服务?
定制开发 / 二次开发

基于 codebjorn/loki 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-30