This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-od-home.php
154 lines (110 loc) · 4.51 KB
/
template-od-home.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
148
149
150
151
<?php
/**
* Template Name: [OD] Homepage
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
$context = Timber::context();
$timber_post = Timber::query_post();
$context['post'] = $timber_post;
$defaultimage = get_template_directory_uri() . '/flavors/optimaaldigitaal/assets/images/od-default.jpg';
if ( 'ja' === get_field( 'gerelateerde_content_toevoegen' ) ) {
$context['related'] = related_block_get_data();
// tipkaarten zien er niet prettig uit als het kolomaantal niet op 4 staat op de homepage
$context['related']['columncounter'] = 4;
}
$spotlightblocks = spotlight_block_get_data();
if ( $spotlightblocks ) {
$context['spotlight'] = $spotlightblocks;
}
$teaserblocks = teaser_block_get_data();
if ( $teaserblocks ) {
$context['teaserblocks'] = $teaserblocks;
}
//$imagesize_for_thumbs = 'thumb-cardv3';
//$imagesize_for_thumbs = BLOG_SINGLE_DESKTOP;
$imagesize_for_thumbs = IMAGESIZE_16x9;
// events selecteren
if ( class_exists( 'EM_Events' ) ) {
$args = array(
'limit' => 2,
'array' => true
);
$events = EM_Events::get( $args );
if ( $events ) {
if ( get_option( 'dbem_events_page' ) ) {
// de titel boven dit blok is exact gelijk aan de pagina-titel van de event page
$context['actueel']['events']['title'] = get_the_title( get_option( 'dbem_events_page' ) );
$context['actueel']['events']['cta']['url'] = get_permalink( get_option( 'dbem_events_page' ) );
$context['actueel']['events']['cta']['title'] = get_the_title( get_option( 'dbem_events_page' ) );
$context['actueel']['events']['cta']['url'] = get_permalink( get_option( 'dbem_events_page' ) );
}
foreach ( $events as $event ):
$item = array();
$item['title'] = $event['event_name'];
$item['url'] = get_the_permalink( $event['post_id'] );
$image = get_the_post_thumbnail_url( $event['post_id'], $imagesize_for_thumbs );
$event_start_date = $event['event_start_date'];
$event_start_time = $event['event_start_time'];
$event_end_date = $event['event_end_date'];
$event_end_time = $event['event_end_time'];
$event_end_datetime = strtotime( $event_end_date . ' ' . $event_end_time );
$event_start_datetime = strtotime( $event_start_date . ' ' . $event_start_time );
if ( $event_start_datetime === $event_end_datetime ) {
$item['start_date'] = $event_start_datetime;
} elseif ( $event_start_datetime && $event_end_datetime ) {
$item['start_date'] = $event_start_datetime;
$item['end_date'] = $event_end_datetime;
}
$item['arialabel'] = sprintf( _x( '%s op %s', 'Arialabel agenda home', 'gctheme' ), $event['event_name'], date_i18n( get_option( 'date_format' ), $event_start_datetime ) );
if ( ! $image ) {
$item['img'] = $defaultimage;
} else {
$item['img'] = $image;
}
$item['img_alt'] = sprintf( _x( 'Link to %s', 'Arialabel image-link', 'gctheme' ), $item['title'] );
$context['actueel']['events']['items'][] = $item;
endforeach;
}
}
// posts selecteren
$maxnr_posts = 2;
// if ( isset( $context['actueel']['events'] ) ) {
// $maxnr_posts = ( 4 - count( $context['actueel']['events']['items'] ) );
// }
$args = array(
'post_type' => 'post',
'numberposts' => $maxnr_posts,
'post_status' => 'publish',
);
$relatedtips = new WP_Query( $args );
if ( $relatedtips->have_posts() ) {
$counter = 0;
while ( $relatedtips->have_posts() ) {
$relatedtips->the_post();
$item = array();
$item['title'] = $post->post_title;
$item['url'] = get_the_permalink( $post );
$image = get_the_post_thumbnail_url( $post->ID, $imagesize_for_thumbs );
if ( ! $image ) {
$item['img'] = $defaultimage;
} else {
$item['img'] = $image;
}
$item['img_alt'] = sprintf( _x( 'Link to %s', 'Arialabel image-link', 'gctheme' ), $item['title'] );
$context['actueel']['blogs']['items'][] = $item;
}
if ( get_option( 'default_category' ) ) {
$termid = get_option( 'default_category' );
$context['actueel']['blogs']['cta']['url'] = get_category_link( $termid );
$context['actueel']['blogs']['cta']['title'] = get_cat_name( $termid );
} elseif ( get_option( 'page_for_posts' ) ) {
$context['actueel']['blogs']['cta']['url'] = get_permalink( get_option( 'page_for_posts' ) );
$context['actueel']['blogs']['cta']['title'] = get_the_title( get_option( 'page_for_posts' ) );
}
/* Restore original Post Data */
wp_reset_postdata();
}
Timber::render( [ 'od-home.html.twig', 'page.twig' ], $context );