-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-normal.php
310 lines (282 loc) · 8.88 KB
/
single-normal.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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php get_header(); ?>
<main>
<?php
// if ( have_posts() ) :
// while ( have_posts() ) :
the_post();
$post_id = get_the_ID();
$first_cat = get_the_category($post_id);
$rand_number = rand(0,count($first_cat)-1);
$this_cat = $first_cat[$rand_number]->term_id;
$cat_slug = get_category($this_cat)->slug;
// check if cat=book?
$cat_book = false;
for ($x = 0; $x <= count($first_cat)-1; $x++) {
$catItemId = $first_cat[$x]->term_id;
$catItemSlug = get_category($catItemId)->slug;
if ($catItemSlug == 'book'){
$cat_book = true;
break;
}
}
?>
<header class="header-page bg-cat-<?php echo $this_cat; ?> <?php if($cat_book){echo 'header-book';} ?>">
<div class="container">
<div class="row justify-content-center align-items-center">
<?php if (!$cat_book){ ?>
<div class="col-12 col-md-8">
<?php }else{ ?>
<div class="col-md-auto col-12">
<div class="book-cover">
<?php
$bookCover = get_field('post_book_cover',$post_id);
echo wp_get_attachment_image( $bookCover['id'],'medium');
?>
</div>
</div>
<div class="col-md-8 col-12 text-center mt-md-4">
<?php } ?>
<h1 class="page-title">
<?php the_title(); ?>
</h1>
<div class="page-subtitle">
<span>
<i class="icon-folder-open-empty"></i>
<a href="<?php echo esc_url( get_category_link( $this_cat ) ) ?>"><?php echo $first_cat[$rand_number]->name; ?></a>
</span>
<span>
<i class="icon-clock"></i>
<?php
date_default_timezone_set('Asia/Ho_Chi_Minh
');
$from = strtotime($post->post_date);
$today = time();
$difference = floor(($today - $from)/86400); // day
if ((get_field('update',$post_id)==true) & $difference < 7):
echo 'Mới cập nhật';
elseif ($difference == 0):
echo 'Vừa mới đăng';
elseif ($difference < 7):
echo $difference.' ngày trước';
else:
echo the_date('d-m-Y');
endif;
?>
</span>
<?php
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$full_name = '';
if( empty($fname)){
$full_name = $lname;
} elseif( empty( $lname )){
$full_name = $fname;
} else {
//both first name and last name are present
$full_name = "{$lname} {$fname}";
}
?>
<span>
<i class="icon-user-outline"></i>
<a class="author-post" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
<?php echo $full_name; ?>
</a>
</span>
</div>
</div> <!-- /.col -->
</div> <!-- /.row -->
</div> <!-- /.container -->
</header>
<?php get_template_part( 'parts/subscribe-bar' ); ?>
<!-- main content -->
<article class="pt-5">
<div class="container">
<div class="row justify-content-center">
<?php // series
$series = get_the_series($post_id);
$series_id = $series[0]->term_id;
$series_link = get_series_link($series_id);
$series_name = get_series_name($series_id);
if (get_field('display_series',$post_id)==true and $series_id):
?>
<div class="series-sidebar">
<div class="seriesbox sticky-top">
<div class="series-title">
Chủ đề <?php echo '<a target="_blank" href="'.$series_link.'">'.$series_name.'</a>'; ?>
</div>
<ul class="serieslist-ul">
<?php echo get_series_posts(); ?>
</ul>
</div>
</div>
<?php
endif;
?>
<!-- main content -->
<div class="col-12 col-lg-10 col-xl-8 blog-content post-font">
<?php
if (get_field('display_series',$post_id)==true and $series_id):
?>
<div class="series-bar">
Bài này nằm trong loạt bài <?php echo '<a target="_blank" href="'.$series_link.'">'.$series_name.'</a>'; ?>.
</div>
<?php
endif;
?>
<?php
if ($cat_slug == 'tool'){
// only display for cat cong-cu
echo the_excerpt();
?>
<?php } ?>
<?php the_content(); ?>
</div>
<?php
if (get_field('toc_on_sidebar',$post_id)==true):
?>
<div class="toc-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top">
<div>Trong bài này</div>
</nav>
</div>
<?php
endif;
?>
</div> <!-- /row -->
</div> <!-- /container -->
</article>
</main>
<div class="extra-info">
<!-- tags -->
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="tags">
<?php the_tags('',' ',''); ?>
</div>
</div>
</div>
</div>
<!-- sharing buttons -->
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-8 blog-content">
<div class="d-flex alignwide sharing-buttons">
<div class="flex-fill">
<?php
$facebook_url = 'https://www.facebook.com/sharer/sharer.php?u=' . get_the_permalink() . '&title=' . get_the_title() . '';
?>
<a href="javascript:void(0)" onclick="atomicBlocksShare('<?php echo $facebook_url ?>','<?php echo get_the_title() ?>','600','600')" title="Share on facebook">
<div class="item">
<i class="fa fa-facebook" aria-hidden="true"></i>
Chia sẻ trên facebook
</div>
</a>
</div>
<div class="flex-fill">
<?php
$email_url = 'mailto:?subject=' . get_the_title() . '&body=Một bài viết hay trên Math2IT: ' . get_the_title() . ' — ' . get_the_permalink() . '';
?>
<a href="<?php echo $email_url ?>" title="Share via email">
<div class="item">
<i class="fa fa-envelope" aria-hidden="true"></i>
Chia sẻ qua email
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<script>
function atomicBlocksShare( url, title, w, h ){
var left = ( window.innerWidth / 2 )-( w / 2 );
var top = ( window.innerHeight / 2 )-( h / 2 );
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=600, top='+top+', left='+left);
}
</script>
<!-- author's box -->
<?php if (get_field('show_author_box',$post_id)==true): ?>
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-8 blog-content">
<div class="alignwide author-box">
<div class="author-avatar">
<?php
if (get_field('user_avatar','user_'.get_the_author_meta('ID'))):
$avatar = get_field('user_avatar','user_'.get_the_author_meta('ID'));
echo wp_get_attachment_image( $avatar['id'],'thumbnail');
elseif(get_avatar_url(get_the_author_meta('ID'),50) !== FALSE):
$avatar = get_avatar_url(get_the_author_meta('ID'),array("size"=>200));
?>
<img src="<?php echo $avatar; ?>" alt="<?php the_author() ?>'s avatar'">
<?php else: ?>
<img src="<?php echo get_template_directory_uri() ?>/img/author.svg">
<?php endif; ?>
</div>
<div class="author-info">
<div class="author-name">
<?php echo $full_name; ?>
</div>
<div class="author-role">
<?php echo get_field('user_role','user_'.get_the_author_meta('ID')) ?>
</div>
<div class="author-description">
<?php
if (get_the_author_meta('description')){
echo nl2br(get_the_author_meta('description'));
}else{
echo "Một tác giả của Math2IT.";
}
?>
</div>
<div class="author-more">
<a href="mailto:<?php echo get_the_author_meta('user_email') ?>">
<i class="fa fa-envelope" aria-hidden="true"></i>
Email cho <?php if ($fname){echo $fname;}else{ the_author();} ?>
</a>
<a class="author-post" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
<i class="fa fa-files-o" aria-hidden="true"></i>
Xem bài <?php if ($fname){echo $fname;}else{ the_author();} ?> viết
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?><!-- /author-box -->
<!-- related posts -->
<div class="related-post">
<?php
$tags = wp_get_post_tags($post_id);
$tag_ids = array();
set_query_var('typeTitle', '');
set_query_var('customTitle', 'Có thể bạn thích?');
set_query_var('display_category', true);
set_query_var('customURL', '/all' );
$list_post_args = array(
'tag__in' => $tag_ids,
'post__not_in' => array($post_id),
'posts_per_page' => 4,
'orderby' => 'rand',
'post_status' => 'publish'
);
$list_posts = get_posts($list_post_args);
set_query_var('list_posts', $list_posts);
?>
<?php get_template_part( 'parts/cat-layout-photo-title' ); ?>
<?php wp_reset_query(); // reset ?>
</div>
<!-- comments -->
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="comment-section">
<?php comments_template(); ?>
</div> <!-- /comment-section -->
</div>
</div>
</div>
</div> <!-- /div extra info -->
<?php get_footer(); ?>