-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.php
More file actions
284 lines (266 loc) · 8.93 KB
/
box.php
File metadata and controls
284 lines (266 loc) · 8.93 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*
Name: Related Post Box
Author: Nadiar AS -- pabelog.com
Description: Adds Related Post with Img to Thesis.
Version: 2.3.1
Class: related_post_box
*/
class related_post_box extends thesis_box
{
protected function translate()
{
$this->title = __('Related Posts Box', 'thesis');
}
protected function construct()
{
global $thesis;
if (!$this->_display()) return;
add_theme_support('post-thumbnails');
if (empty($thesis->_wp_featured_image_rss)) {
add_filter('the_content', array($this, 'add_image_to_feed'));
$thesis->_wp_featured_image_rss = true;
}
}
protected function options()
{
global $thesis, $_wp_additional_image_sizes;
$options = array(
'full' => __('Full size (default)', 'thesis'),
'thumbnail' => __('Thumbnail', 'thesis'),
'medium' => __('Medium', 'thesis'),
'large' => __('Large', 'thesis')
);
if (!empty($_wp_additional_image_sizes))
foreach ($_wp_additional_image_sizes as $size => $data)
$options[$size] = $size;
return array(
'activate' => array(
'type' => 'checkbox',
'label' => __('Display Related Post with Image', 'thesis'),
'options' => array(
'img1checktext' => __('Click here to activate Related Post with Image', 'thesis'),
),
'default' => array(
'img1checktext' => false,
'html' => ''
)
),
'relatedtype' => array(
'type' => 'radio',
'label' => __('Show by', 'thesis'),
'tooltip' => sprintf(__('Choose by what related post will be displayed. More info at <a href="http://www.wpbeginner.com/wp-themes/how-to-add-related-posts-with-a-thumbnail-without-using-plugins/" target="_blank">WPBegginer</a>(default by category)', 'thesis')),
'options' => array(
'category' => __('By Category', 'thesis'),
'tag' => __('By Tag', 'thesis')
),
'default' => array(
'category' => true,
'html' => ''
)
),
'title' => array(
'type' => 'text',
'width' => 'medium',
'label' => __('Title', 'thesis'),
'tooltip' => sprintf(__('Enter the title of Related Posts you would like to show', 'thesis')),
'default' => ''
),
'container_class' => array(
'type' => 'text',
'width' => 'medium',
'label' => __('Title', 'thesis'),
'tooltip' => sprintf(__('Container class', 'thesis')),
'default' => 'related_posts_containers'
),
'ul_class' => array(
'type' => 'text',
'width' => 'medium',
'label' => __('Title', 'thesis'),
'tooltip' => sprintf(__('ul class', 'thesis')),
'default' => 'related_posts_list'
),
'li_class' => array(
'type' => 'text',
'width' => 'medium',
'label' => __('Title', 'thesis'),
'tooltip' => sprintf(__('li class', 'thesis')),
'default' => 'related_post_item'
),
'number' => array(
'type' => 'text',
'width' => 'tiny',
'label' => __('Max Number of Related Post', 'thesis'),
'tooltip' => sprintf(__('Enter the Number of Related Post you want to display(leave blank for 3 posts)', 'thesis')),
'default' => '4'
),
'characters' => array(
'type' => 'text',
'width' => 'tiny',
'label' => __('Maximum of Characters for the Title', 'thesis'),
'tooltip' => sprintf(__('Enter Maximum of Characters for the Title(leave blank for 64 character)', 'thesis')),
'default' => '64'
),
'size' => array(
'type' => 'select',
'label' => __('Featured Image Size', 'thesis'),
'tooltip' => sprintf(__('Choose the size of the Feature Image for this location. The list includes <a href="%s">WordPress standard image sizes</a> and any other registered image sizes.', 'thesis'), admin_url('options-media.php')),
'options' => $options,
'default' => 'full'
),
'link' => array(
'type' => 'checkbox',
'options' => array(
'link' => __('Link image to post', 'thesis')
),
'default' => array(
'link' => true
)
),
'is_active_ads' => array(
'type' => 'checkbox',
'label' => __('Activate ads?', 'thesis'),
'options' => array(
'img1checktext' => __('Click here to activate ads', 'thesis'),
),
'default' => array(
'img1checktext' => false,
'html' => ''
)
),
'ads' => array(
'type' => 'textarea',
'label' => __('Your ads code', 'thesis'),
'tooltip' => sprintf(__('The best match is 300x600 ads code', 'thesis')),
'code' => true,
'default' => ''
),
'is_active_native_ads' => array(
'type' => 'checkbox',
'label' => __('Activate native ads?', 'thesis'),
'options' => array(
'img1checktext' => __('Click here to activate native ads', 'thesis'),
),
'default' => array(
'img1checktext' => false,
'html' => ''
)
),
'native_ads' => array(
'type' => 'textarea',
'label' => __('Your native ads code here', 'thesis'),
'tooltip' => sprintf(__('The best match is like related_post_item class', 'thesis')),
'code' => true,
'default' => ''
)
);
}
public function html()
{
global $thesis, $post;
// get options
$options = $thesis->api->get_options($this->_options(), $this->options);
// activate
if ($options['activate']) {
/*
* CORE CODE
*/
$orig_post = $post;
global $post;
$title = !empty($this->options['title']) ? $this->options['title'] : '';
$number = !empty($this->options['number']) ? $this->options['number'] : '4';
$size = !empty($this->options['size']) ? $this->options['size'] : 'thumbnail';
$ads = !empty($this->options['ads']) ? $this->options['ads'] : '';
$is_active_ads = !empty($this->options['is_active_ads']) ? $this->options['is_active_ads'] : false;
$native_ads = !empty($this->options['native_ads']) ? $this->options['native_ads'] : '';
$is_active_native_ads = !empty($this->options['is_active_native_ads']) ? $this->options['is_active_native_ads'] : false;
$title_chars = !empty($this->options['characters']) ? $this->options['characters'] : '64';
$dom_container_class = !empty($this->options['container_class']) ? $this->options['container_class'] : 'related_posts_containers';
$dom_ul_class = !empty($this->options['li_class']) ? $this->options['li_class'] : 'related_posts_list';
$dom_li_class = !empty($this->options['ul_class']) ? $this->options['ul_class'] : 'related_post_item';
if ($options['relatedtype'] == 'tag') {
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach ($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args = array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => $number, // Number of related posts that will be shown.
'caller_get_posts' => 1
);
}
} else {
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach ($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args = array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => $number, // Number of related posts that will be shown.
'caller_get_posts' => 1
);
}
} // end if
$my_query = new wp_query($args);
if ( $my_query->have_posts() ) { ?>
<div id="relatedposts">
<h3 class="related_post_label"><?php echo $title; ?></h3>
<div style="width: 100%">
<!-- First Column --> <?php
if ($is_active_ads) { ?>
<div class="adpad">
<?php echo $ads; ?>
</div> <?php
} ?>
<!-- Second Column Will be related post-->
<div class="<?php echo $dom_container_class; ?>">
<!-- Related Post Begin -->
<ul class="<?php echo $dom_ul_class; ?>">
<?php while ($my_query->have_posts()) {
$my_query->the_post(); ?>
<!-- related post <li> -->
<li class="<?php echo $dom_li_class; ?>">
<div class="relatedthumb">
<?php
if (!isset($this->options['link'])) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo the_title(); ?>"><?php the_post_thumbnail($options['size']); ?></a>
<?php
} else {
the_post_thumbnail($options['size']);
}
?>
</div>
<div class="relatedcontent">
<p class="caption aligncenter italic"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php
if (strlen($post->post_title) > $title_chars) {
echo substr(the_title($before = '', $after = '', false), 0, $title_chars) . '...';
} else {
the_title();
} ?></a></p>
</div>
</li>
<?php
} // end while
if ( $is_active_native_ads ) { ?>
<li class="<?php echo $dom_li_class; ?>">
<?php echo $native_ads; ?>
</li>
<?php
} ?>
</ul>
<!-- Related Post End -->
</div>
</div>
</div>
<?php
} // end if query
} // end if activate
$post = $orig_post;
wp_reset_query();
/*
* CORE CODE END
*/
} // end public funtion
}