-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.php
executable file
·49 lines (40 loc) · 1.55 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
<?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 main.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
*/
use P4\MasterTheme\Context;
use P4\MasterTheme\Post;
use P4\MasterTheme\ListingPage;
use Timber\Timber;
$context = Timber::get_context();
$templates = [ 'index.twig' ];
if (is_home()) {
$post = new Post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post->set_data_layer();
$data_layer = $post->get_data_layer();
$page_meta_data = get_post_meta($post->ID);
$page_meta_data = array_map(fn ($v) => reset($v), $page_meta_data);
$context['title'] = ( $page_meta_data['p4_title'] ?? '' )
? ( $page_meta_data['p4_title'] ?? '' )
: html_entity_decode($context['wp_title'] ?? '');
$context['posts'] = Timber::get_posts();
Context::set_header($context, $page_meta_data, $context['title']);
Context::set_background_image($context);
Context::set_og_meta_fields($context, $post);
Context::set_campaign_datalayer($context, $page_meta_data);
Context::set_utm_params($context, $post);
array_unshift($templates, 'all-posts.twig');
$page = new ListingPage($templates, $context);
} else {
Timber::render($templates, $context);
}