定制 ixa/layout 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ixa/layout

Composer 安装命令:

composer require ixa/layout

包简介

WordPress library that provides basic support to use layouts in themes

README 文档

README

Build Status

Ixa Layout is a WordPress library that provides basic support to use layouts in themes.

Requirements

Besides PHP 5.3 you need a WordPress installation with Composer, for example, Ixa Wordpress Starter.

Installation

Require as dependency in composer.json

"require": {
    ...
    "ixa/layout" : "0.3"
} 

And register the filter in <your-theme>/functions.php file:

Ixa\Layout\LayoutFilter::register();

After registering the filter you can decorate your views with layouts. By default layout folder is <your-theme>/layouts, it can be changed using the first parameter: LayoutFilter::register($customDir).

Views

In the layout pattern, a view is the template that holds the main content. In WordPress terms are the files loaded following template hierarchy.

Regular views have a structure similar to

<?php  get_header() ?>

<main>
    <?php the_post() ?>
    <?php the_title() ?>
    <?php the_content() ?>
</main>

<?php  get_sidebar() ?>
<?php  get_footer() ?>

Using IxaLayout we can get rid of all unrelated templates tag, writing only the main content:

<?php the_post() ?>
<?php the_title() ?>
<?php the_content() ?>

IxaLayout will parse the content and display when the layout call yield_content() function.

Layouts

Layouts are wrappers for views, they use the same syntax and functions that regular WordPress templates. They also have the covenient function yield_content() which loads the parsed content of the view.

A tipical layout would be:

<?php  get_header() ?>

<main>
    <?php yield_content() ?>
</main>

<?php  get_sidebar() ?>
<?php  get_footer() ?>

Layout Selection

All layouts must be placed under /layouts folder. default.php layout is requiered since is the fallback in case selected layout is not found.

Within a view we can set the layout we want to apply using layout() function. The first parameter is the relative path, without extension of the layout:

layout('services')

Ixa Layout Will try to load <your-theme>/layouts/services.php file, if it doesn't exists will fallback to <your-theme>/layouts/default.php. In case no layout is found an Ixa/Layout/LayoutNotFoundException wil be thrown.

How Ixa Layout works

Ixa Layout is a filter attached to template_include with a priority of 10000 in order to be run after all filters, then loads and saves the view selected by WordPress following template hierarchy and returns the path to the layout that WordPress loads.

Ixa Layout isn't a plugin that's why it requires to be autoloaded by Composer and registered in your functions.php file. This way we can have consistent code across environments because we don't have to wait the user to activate the plugin.

Development status

It's not fully tested and may collapse with plugins or themes that use template_include filter or ob_get_contents() function.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固