-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
executable file
·147 lines (117 loc) · 4.48 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* The main template file
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
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;
}
$templates = array('index.twig');
$context = Timber::get_context();
$context['posts'] = Timber::get_posts(); // Can be empty! (404, single, page)
$context['pagination'] = Timber::get_pagination();
////////////////////////////////////////////////////////////////////////////////
// 404
if (is_404()) {
array_unshift($templates, '404.twig');
$context['title'] = "Oups, petit problème !";
////////////////////////////////////////////////////////////////////////////////
// SINGLE
} else if (is_single()) { // Or is_singular()?
if (post_password_required($post->ID)) {
array_unshift($templates, 'single-password.twig');
} else {
array_unshift($templates,
'single-' . $post->ID . '.twig',
'single-' . $post->post_type . '.twig',
'single.twig'
);
}
$post = Timber::query_post();
$context['post'] = $post;
////////////////////////////////////////////////////////////////////////////////
// PAGE
} else if (is_page()) {
array_unshift($templates,
'page-' . $post->post_name . '.twig',
'page.twig',
'index.twig'
);
$post = new TimberPost();
$context['post'] = $post;
if (is_front_page()) {
array_unshift($templates, 'front-page.twig');
$args = array(
'posts_per_page' => 6,
'orderby' => 'date',
);
$context['latest_posts'] = Timber::get_posts($args);
}
////////////////////////////////////////////////////////////////////////////////
// ARCHIVE
} else if (is_archive()) {
array_unshift($templates, 'archive.twig');
$context['title'] = 'Articles';
// Archive by period
if (is_day()) {
$context['title'] = 'Articles par date : ' . get_the_date('D M Y');
} else if (is_month()) {
$context['title'] = 'Articles par date : ' . get_the_date('M Y');
} else if (is_year()) {
$context['title'] = 'Articles par date : ' . get_the_date('Y');
// Archive by tag or category
} else if (is_tag()) {
$context['title'] = 'Articles avec le tag "' . single_tag_title('', false) . '"';
} else if (is_category()) {
array_unshift($templates, 'archive-' . get_query_var('cat') . '.twig');
$context['title'] = 'Articles dans la catégorie ' . single_cat_title('', false);
// Archive by author
} else if (is_author()) {
array_unshift($templates, 'author.twig');
if (isset($wp_query->query_vars['author'])) {
$author = new TimberUser($wp_query->query_vars['author']);
$context['author'] = $author;
$context['title'] = $author->name();
}
// Archive by custom post type
} else if (is_post_type_archive()) {
array_unshift($templates, 'archive-' . get_post_type() . '.twig');
$context['title'] = post_type_archive_title('', false);
}
////////////////////////////////////////////////////////////////////////////////
// SEARCH
} else if (is_search()) {
array_unshift($templates,
'search.twig',
'archive.twig'
);
$post_types = get_post_types();
//Display Product results in first
if (in_array('product', $post_types)) {
unset($post_types['product']);
array_unshift($post_types, 'product');
}
// Results group by post_type
foreach($context['posts'] as $post) {
$context['post_type_'.$post->post_type][] = $post;
}
$context['post_types'] = $post_types;
$context['title'] = count(Timber::get_posts()) . ' résultat(s) de recherche pour "' . get_search_query() . '"';
////////////////////////////////////////////////////////////////////////////////
// INDEX
} else {
$context['title'] = 'Blog';
}
////////////////////////////////////////////////////////////////////////////////
// TIMBER TEMPLATES RENDERING
Timber::render($templates, $context);