-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
116 lines (88 loc) · 2.49 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* /index
*
* @package WordPress
* @subpackage 19h47
* @author Jérémy Levron <[email protected]> (http://19h47.fr)
*/
if ( ! class_exists( 'Timber' ) ) {
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
}
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
// Roles
$roles = get_field( 'role' );
if ( ! empty( $roles ) ) {
foreach ( $roles as $role ) {
$context['work']['details']['roles'][] = $role->name;
}
}
// Clients
$clients = get_field( 'client' );
if ( ! empty( $clients ) ) {
foreach ( $clients as $client ) {
$context['work']['details']['clients'][] = $client->name;
}
}
// Link
$link = get_field( 'link' );
if ( ! empty( $link ) ) {
$context['work']['details']['link'] = $link;
}
// Repository
$repository = get_field( 'repository' );
if ( ! empty( $repository ) ) {
$context['work']['details']['repository'] = $repository;
}
$templates = array( 'index.twig' );
if ( is_404() ) {
array_unshift( $templates, 'pages/404.twig' );
}
// Single work
if ( is_singular( 'work' ) ) {
$work = new WP_Query(
array(
'post_type' => 'work',
'posts_per_page' => -1,
)
);
foreach ( $work->posts as $key => $value ) {
if ( $value->ID === $post->ID ) {
$next_object = $work->posts[ $key - 1 ];
$previous_object = $work->posts[ $key + 1 ];
}
}
if ( $next_object === null ) {
$next_object = $work->posts[ count( $work->posts ) - 1 ];
}
if ( $previous_object === null ) {
$previous_object = $work->posts[0];
}
$context['work']['previous'] = array(
'id' => $previous_object->ID,
'title' => strip_tags( str_replace( '"', '', $previous_object->post_title ) ),
'link' => get_permalink( $previous_object->ID ),
'color' => get_field( 'color', $previous_object->ID ),
'slug' => $previous_object->post_name,
);
$context['work']['next'] = array(
'id' => $next_object->ID,
'title' => strip_tags( str_replace( '"', '', $next_object->post_title ) ),
'link' => get_permalink( $next_object->ID ),
'color' => get_field( 'color', $next_object->ID ),
'slug' => $next_object->post_name,
);
array_unshift( $templates, 'pages/work-single.twig' );
}
// Archive work
if ( is_post_type_archive( 'work' ) ) {
array_unshift( $templates, 'pages/work-archive.twig' );
}
// Home
if ( is_home() ) {
array_unshift( $templates, 'pages/thoughts.twig' );
}
Timber::render( $templates, $context );