Skip to content

Instantly share code, notes, and snippets.

View jarednova's full-sized avatar
🗽

Jared Novack jarednova

🗽
View GitHub Profile
  • Whatever
@jarednova
jarednova / gist:6095599
Created July 27, 2013 17:32
Twig / Timber if/else
{% if post.thumbnail %}
<img src="{{post.thumbnail.src}}" />
{% elseif post.heroimage %}
<img src="{{post.heroimage.src}}|resize(300, 300)" />
{% else %}
<img src="/wp-content/themes/mytheme/default-image.jpg" />
{% endif %}
Nice dfsd
dfasd
@jarednova
jarednova / client-article.php
Last active July 13, 2016 12:33
### Let's maximize best practice. From my perspective this means making objects out of our Article so we can handle they byline permutations:
<?php
/* client-article.php */
class ClientArticle extends TimberPost {
function writers(){
return $this->get_terms('writers', true, 'ClientWriter');
}
<?php
$data = Timber::get_context();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=2&paged='.$paged);
$posts = Timber::get_posts();
$data['posts'] = $posts;
$data['pagination'] = Timber::get_pagination();
Timber::render('date.twig', $data);
<h1>Congratulations to {{name}}</h1>
<p>You're really great so we're giving you a prize of {{prize}}</p>
{% for sub_post in TimberPost(post.get_field('my_repeater').sub_post) %}
<h2>{{sub_post.title}}</h2>
{% endfor %}
<?php
get_header();
echo 'whatever'.get_the_title();
the_content();
$data = array();
$data['post'] = new TimberPost();
Timber::render('article-meta.twig', $data);
<?php
$context = Timber::get_context();
$context['work'] = Timber::get_posts('post_type=work&numberposts=25');
$context['posts'] = Timber::get_posts();
Timber::render('index.twig', $context);