-
Notifications
You must be signed in to change notification settings - Fork 0
/
single.php
62 lines (56 loc) · 1.55 KB
/
single.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
$context = Timber::context();
$single_post = Timber::get_post();
$context['post'] = $single_post;
/** Get all the POST TYPES terms */
$all_posttype_terms = get_the_terms( $single_post->ID, 'post_types' );
$context['all_posttype_terms'] = $all_posttype_terms;
if ( $all_posttype_terms ) {
$context['parent_posttype_term'] = reset( $all_posttype_terms );
}
/**
* Get Most recent posts in category but not posts that are opinions or offsite
*
* Another Option:
* $current_category = $current_category[0]->cat_ID;
*/
$current_category = get_the_category( $single_post->ID );
/**
* Query Timber
*
* Example Custom Query:
* 'tax_query' => array(
* array(
* 'taxonomy' => '',
* 'terms' => array(
* ),
* 'field' => 'slug',
* 'operator' => 'NOT IN',
* ),
* ),
*/
$context['latest_posts'] = Timber::get_posts(
array(
'post_type' => 'post',
'numberposts' => 3,
'offset' => 0,
/** 'category__in' => array( $current_category ), */
'post_status' => 'publish',
'order' => 'DESC',
'post__not_in' => array( $single_post->ID ),
)
);
if ( post_password_required( $single_post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $single_post->ID . '.twig', 'single-' . $single_post->post_type . '.twig', 'single.twig' ), $context );
}