-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteaser.php
87 lines (82 loc) · 2.6 KB
/
teaser.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
<?php /* This part of code displays the teaser for the theme.
* It accepts some external variables as parameters:
* Please include this file with
* require(locate_template('circles.php'));
* You can set the following variables:
* $teaser_name: Name of the category containing the teaser posts
* or
* $teaser_id: ID of the category containing the news posts
**/
?>
<?php
$teaser_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1
);
if (isset($teaser_name))
{
$teaser_args['category_name'] = $teaser_name;
$teaser_id = get_cat_id($teaser_name);
} else if (isset($teaser_id)) {
$teaser_args['cat'] = $teaser_id;
} else {
$teaser_args['category_name'] = 'teaser';
$teaser_id = get_cat_id('teaser');
}
$teaser_query = new WP_Query( $teaser_args );
$imgAvail = false;
$first_img = false;
while( $teaser_query->have_posts() ) {
$teaser_query->the_post();
$categories = get_the_category();
$show = false;
if ($categories)
{
foreach ($categories as $category) {
if ($category->term_id == $teaser_id)
{
$show = true;
break;
}
}
}
$startDate = DateTime::createFromFormat('Ymd', get_field( 'show_start' ));
$endDate = DateTime::createFromFormat('Ymd', get_field( 'show_end' ));
$nowDate = new DateTime("now");
if ($show == true && $startDate <= $nowDate && $nowDate <= $endDate)
{
if ($imgAvail == false)
{
echo '<div class="flexslider">' . "\n";
echo '<ul class="slides"> . "\n"';
$imgAvail = true;
$first_img = get_field( 'show_image' );
}
echo '<li>' . "\n";
if (strlen(get_field('externer_link')) > 0) {
echo '<a href="' . get_field('externer_link') . '">' . "\n";
} else if (!is_null(get_field('link')) && strlen(get_field('link')) > 0) {
echo '<a href="' . get_field('link') . '">' . "\n";
}
echo '<img src="';
echo the_field( 'show_image' );
echo '" />' . "\n";
if ((!is_null(get_field('link')) && strlen(get_field('link')) > 0) ||
strlen(get_field('externer_link')) > 0) {
echo '</a>' . "\n";
}
echo '</li>' . "\n";
}
}
if ($imgAvail == true)
{
echo '</ul></div>' . "\n";
if ($first_img !== false)
{
echo '<noscript><img src="';
echo the_field( 'show_image' );
echo '" style="width: 98%" /></noscript>' . "\n";
}
}
?>