Classy is a framework for building wordpress themes, based on Blade template engine. It's fast with beautiful architecture that allows you to write less code and focus more on project itself. It doesn't provide frontend boilerplate, since every project needs its own, instead it handles all architecture, providing an elegant way to separate logic from view.
Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. All Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.
@extends('layout.default')
@section('content')
@if ($post)
<article>
<h1>{{ $post->title() }}</h1>
<section class="body">
{{ $post->content() }}
</section>
</article>
@endif
@stop
The biggest problem with wordpress theme development is that you always need to repeat same code. New approach, that assumes that template data will be collected and prepared separately from actual render allows you to have the project structured more accurate.
ClassyTemplate
repeats the wordpress template hierarchy and uses it separately for scopes and templates. This allows to use the same scope with different templates and different scopes with the same template.
- Navigate to your WordPress themes directory
cd ~/Sites/mysite/wp-content/themes
- Clone repository
git clone [email protected]:anrw/classy.git
- Navigate to it
cd classy
- Install composer dependencies
composer install
Theme config file is located in app/config.php
. This is a place where you can easily registes custom post types, taxonomies, post formats, set up textdomain, current environment and much more. We recommend you to have is initialised this way, however this is not strict rule and everything is up to you :)
$post_types
is a simple array. To insert a custom post type just add a new value like:
$post_types = array(
'gallery' => array(
'config' => array(
'public' => true,
'exclude_from_search' => true,
'menu_position' => 20,
'has_archive' => true,
'supports'=> array(
'title',
'editor',
'page-attributes',
),
'show_in_nav_menus' => true,
),
'singular' => 'Gallery',
'multiple' => 'Galleries',
)
)
The structure is the same as for register_post_type
function, described in https://codex.wordpress.org/Post_Formats
with one exception that we have added Singular
and Multiple
keys to generate all required labels automatically.
To add a post format, you need to insert its name in $post_formats
array.
$post_formats = array(
'aside',
'gallery',
'link'
);
For more reference please visit: https://codex.wordpress.org/Post_Formats
Similar to $post_types
, $taxonomies
is an array. To insert a taxonomy just add a new value like:
$taxonomies = array(
'gallery-category' => array(
'for' => array('gallery'),
'config' => array(
'sort' => true,
'args' => array('orderby' => 'term_order'),
'hierarchical' => true,
),
'singular' => 'Category',
'multiple' => 'Categories',
)
)
The structure is the same as for register_taxonomy
function, described in https://codex.wordpress.org/Taxonomies
with one exception that we have added Singular
and Multiple
keys to generate all required labels automatically.
Find $sidebars
variable. The array key means sidebar id, but the value is its title
$sidebars = array(
'general-sidebar' => 'General Sidebar'
);
Here what is under the hood:
foreach ( $sidebars as $id => $title ) {
register_sidebar(
array(
'id' => $id,
'name' => __($title, $domain),
'description' => __($title, $domain),
'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-inner">',
'after_widget' => '</div></div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
)
);
}
To register a template you need simply to put {{-- Template Name: Example --}}
at the top of your blade file.
We recommend you to structure your templates in one of this ways:
- views/
page
/template-name
.blade.php - views/
templates
/template-name
.blade.php - views/
template-name
/template-name
.blade.php
Wordpress: 4.5+ PHP: 5.4+