Last active
July 13, 2016 12:33
-
-
Save jarednova/6306689 to your computer and use it in GitHub Desktop.
### Let's maximize best practice. From my perspective this means making objects out of our Article so we can handle they byline permutations:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* client-article.php */ | |
class ClientArticle extends TimberPost { | |
function writers(){ | |
return $this->get_terms('writers', true, 'ClientWriter'); | |
} | |
function writer(){ | |
$writers = $this->writers(); | |
return $writers[0]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ClientWriter extends TimberTerm { | |
function get_title(){ | |
$now = get_the_tiem('U'); | |
foreach($titles as $title){ | |
if (strtotime($title['start_date']) < $now && strtotime($title['end_date']) > $now){ | |
return $title; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* single.php */ | |
require_once('client-article.php'); | |
require_once('client-writer.php'); | |
$data = Timber::get_context(); | |
$data['post'] = new ClientArticle(); | |
Timber::render('single.twig', $data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="meta-byline source">By | |
{% for writer in post.writers %} | |
<a href="{{writer.link}}" class="writer-name">{{writer.name}}</a> | |
{% endfor %} | |
{% if post.writers|length == 1 %} | |
<span class="writer-title">{{post.writer.title}}</span> | |
{% else %} | |
<span class="writer-title">Staff Writer</span> | |
{% endif %} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* I'm being as efficent as possible -- I'm assuming that this would reference PHP files as well that don't extend Timber */ | |
<div class="meta-byline source">By | |
<?php foreach($post->writers() as $writer){ ?> | |
<a href="<?= $writer->link(); ?>" class="writer-name"><?= esc_attr($writer->name()); ?></a> | |
<?php } ?> | |
<?php if (count($post->writers()) == 1): ?> | |
<span class="writer-title"><?= esc_attr($post->writer()->title); ?></span> | |
<?php else: ?> | |
<span class="writer-title">Staff Writer</span> | |
<?php endif; ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment