Ivan Villa
Designer learning front end development
Work at Scribe / Web Design
Free Code Camp Sacramento / Active Member
Wordpress core application for managing content for the website.
what the user can see and interact with.
** Don't Really Need to master PHP Language **
<?php the_author(); ?>
<?php comment_author_link(); ?>
<?php the_title(); ?>
build the wordpress way
allows you to write your HTML using Twig Template Engine Seperate from PHP
$context = Timber::get_context();
$context['flavor'] = 'Vanilla';
$context['post'] = new Timber/Post();
Timber::render('single.twig', $context);
{% extends "base.twig" %}
{% block content %}
<h1 class="big-title">{{flavor}}</h1>
<h2>{{post.title}}</h2>
<img src="{{post.thumbnail.src}}" />
<div class="body"> {{post.content}} </div>
{% endblock %}
my-theme/views/single.twig
my-theme/single.php
<?php
$thumb_id = get_post_thumbnail_id($post->ID);
$url = wp_get_attachment_url($thumb_id);
?>
<img src="<?php echo $url; ?>" alt="Thumbnail for Timber" />
<?php ... ?>
<img src="{{post.thumbnail.src}}" alt="Thumbnail for Timber" />
Wordpress Way
Twig Way
<?php the_content() ?> => {{ post.content }}
<?php the_permalink() ?> => {{ post.link }}
<?php the_title() ?> => {{ post.title }}
<?php get_the_tags() ?> => {{ post.tags }}
As code gets more complex its easy to get lost. Keeping your code organized is a good idea
Logic (getting Data from WP)
Presentations (displaying)
Like Underscores, but written for Timber.
If you just want to do a simple module in your site, you can use timber just for that.
//Gets the Data
$data['menu'] = new TimberMenu();
// Twig Template
{% for item in menu.items %}
<li><a href="{{ item.link }}">{{ item.title }}</a></li>
{% endfor %}
By Ivan Villa