-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpbenelux_sponsors_widget.php
185 lines (171 loc) · 5.28 KB
/
phpbenelux_sponsors_widget.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
Plugin Name: PHPBenelux Sponsors
Version: 1.0
Plugin URI: http://phpbenelux.eu
Description: Sponsor plugin
Author: Martin de Keijzer
Author URI: http://phpbenelux.eu/
*/
/**
* Remove bs- css class prefixes to enable bootstrap horizontal layout
*/
add_action( 'widgets_init', 'phpbenelux_sponsors_widget_init' );
function phpbenelux_sponsors_widget_init() {
register_widget( 'phpbenelux_sponsors_widget' );
}
class phpbenelux_sponsors_widget extends WP_Widget
{
/**
* phpbenelux_sponsors_widget constructor.
*/
public function __construct()
{
$widget_details = array(
'classname' => 'phpbenelux_sponsors_widget',
'description' => 'Shows the sponsors for PHPBenelux Conference'
);
parent::__construct( 'phpbenelux_sponsors_widget', 'PHPBenelux sponsors Widget', $widget_details );
}
/**
* FunctionDescription
*
* @param array $instance
*
* @return string|void
*/
public function form( $instance ) {
// Backend Form
}
/**
* FunctionDescription
*
* @param array $new_instance
* @param array $old_instance
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
return $new_instance;
}
/**
* FunctionDescription
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
?>
<div class="bs-row sponsors-widget">
<div class="bs-col-md-5">
<?php echo $this->renderSponsors('platinum', 'bs-col-md-12', false, 'Platinum'); ?>
</div>
<div class="bs-col-md-7">
<div class="bs-row">
<?php echo $this->renderSponsors('gold', 'bs-col-md-4', false, 'Gold'); ?>
</div>
<div class="bs-row">
<?php echo $this->renderSponsors('silver', 'bs-col-md-3', false, 'Silver'); ?>
</div>
</div>
<div class="bs-col-md-12">
<?php echo $this->renderCustomSponsors('bs-col-md-4'); ?>
</div>
</div>
<?php
}
/**
* FunctionDescription
*
* @param $colValue
*/
public function renderCustomSponsors($colValue) {
$args = array(
'numberposts' => -1,
'post_type' => 'sponsor',
'meta_query' => array (
array (
'key' => 'sponsor_type',
'value' => array('platinum', 'gold', 'silver'),
'compare' => 'NOT IN',
)
),
);
$the_query = new WP_Query( $args );
$this->renderQueryResults($the_query, 'custom', $colValue, true, 'Custom');
}
/**
* FunctionDescription
*
* @param $type
* @param $colValue
* @param bool $withLabel
* @param string $header
*/
public function renderSponsors($type, $colValue, $withLabel = false, $header = '') {
$args = array(
'numberposts' => -1,
'post_type' => 'sponsor',
'meta_key' => 'sponsor_type',
'meta_value' => $type
);
$the_query = new WP_Query( $args );
$this->renderQueryResults($the_query, $type, $colValue, $withLabel, $header);
}
/**
* FunctionDescription
*
* @param WP_Query $the_query
* @param $type
* @param $colValue
* @param $withLabel
* @param string $header
*/
protected function renderQueryResults(WP_Query $the_query, $type , $colValue, $withLabel, $header = '')
{
if ($the_query->have_posts()) {
?>
<header class="post-heading">
<div class="post-title-wrapper">
<h2 class="post-title"><?=$header?></h2>
</div>
</header>
<div class="bs-row <?=$type?>-logos"><?php
while ($the_query->have_posts()) {
$the_query->the_post();
$sponsorUrl = get_field('direct_url');
$hasDirectUrl = true;
if (empty($sponsorUrl)) {
$sponsorUrl = get_the_permalink();
$hasDirectUrl = false;
}
?>
<a href="<?php echo $sponsorUrl; ?>"<?php if ($hasDirectUrl) { ?> target="_blank" <?php } ?>>
<div class="<?=$colValue?>">
<div class="sponsorlogo">
<?php
if ( has_post_thumbnail() ) {
?>
<img src="<?php the_post_thumbnail_url('medium_large'); ?>" />
<?php
} else {
the_title();
}
?>
<?php if($withLabel === true) {
?>
<div class="sponsor-label">
<?php echo get_field('sponsor_type'); ?>
</div>
<?php
} ?>
</div>
</div>
</a>
<?php
}
?></div><?php
}
wp_reset_query();
}
}