WordPress Templates Are Broken!
(But We Can Fix Them)
Jared Novack
From STL now in Boston
WordPress dev since 2010
I love WordPress
Things to love about WordPress
Oh, love that Admin
Things to love about WordPress
The best community
Things to love about WordPress
Clear and sensible template hierarchy
- index.php
- home.php
- page.php
- page-about.php
- single.php
- single-portfolio.php
- archive-portfolio.php
TwentyTen Theme
TwentyTwelve Theme
We have a word for this...
I'm a WordPress Developer
Ruby on Rails
Django
Laravel/Symfony/Zend
Node.js
Yes, even Drupal
A Template Language
<div class="entry">
<h1>Hello World!</h1>
<div class="body">
This is my sample post, right here.
</div>
</div>
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
<div class="entry">
<h1>{{post.title}}</h1>
<div class="body">
{{post.content}}
</div>
</div>
MVC
Model
Your data
View
What it looks like
Controller
Logic.
MVC in WordPress
Model
WordPress Database
View
The .php files inside the theme folder
Controller
The .php files inside the theme folder
So we get this
Um, this is bad ...
For WordPress developers
... because my code is a mess
Twig + WordPress
In normal WordPress
single.php
With WordPress Timber
single.php
single.twig
- Make a box
- Fill it with data
- Send it to the template
What can Twig do for you?
- Variables
- Simple Logic
- Filters
Twig Features
Variables
- Title
- Permalink
- ISBN (custom field)
- <h1><?php echo get_the_title(); ?></h1>
- <a href="<?php echo get_permalink(); ?>">My title</a>
- The ISBN is: <?php echo get_post_meta(get_the_ID(), 'isbn', true); ?>
- <h1>{{post.title}}</h1>
- <a href="{{post.permalink}}"> My Title </a>
- The ISBN is: {{post.isbn}}
Twig Features
Simple Logic
- Conditionals
- Loops
- Includes
Twig Features
Template Extension
Contribute to the code
Help with examples + documentation
Send me your sites!
Star Timber on GitHub!