/
template-tags.php
870 lines (764 loc) · 28.5 KB
/
template-tags.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features.
*
* @license GPL 2.0
*/
if ( ! function_exists( 'siteorigin_corp_author_box' ) ) {
/**
* Display the post author biographical info on single posts.
*/
function siteorigin_corp_author_box() { ?>
<div class="author-box">
<div class="author-avatar">
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 100 ); ?>
</a>
</div><!-- .author-avatar -->
<div class="author-description">
<h3><?php echo get_the_author(); ?></h3>
<span class="author-posts">
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
<?php esc_html_e( 'View posts by ', 'siteorigin-corp' );
echo get_the_author(); ?>
</a>
</span>
<?php if ( get_the_author_meta( 'description' ) ) { ?>
<div><?php echo wp_kses_post( get_the_author_meta( 'description' ) ); ?></div>
<?php } ?>
</div><!-- .author-description -->
</div><!-- .author-box -->
<?php
}
}
if ( ! function_exists( 'siteorigin_corp_breadcrumbs' ) ) {
/**
* Display's breadcrumbs supported by Breadcrumb NavXT, Rank Math, and Yoast SEO.
*/
function siteorigin_corp_breadcrumbs() {
if ( siteorigin_page_setting( 'overlap' ) != 'disabled' ) {
return;
}
siteorigin_settings_breadcrumbs();
}
}
add_action( 'siteorigin_corp_content_top', 'siteorigin_corp_breadcrumbs' );
if ( ! function_exists( 'siteorigin_corp_comment' ) ) {
/**
* The callback function for wp_list_comments in comments.php.
*
* @see https://codex.wordpress.org/Function_Reference/wp_list_comments.
*/
function siteorigin_corp_comment( $comment, $args, $depth ) {
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<?php $type = get_comment_type( $comment->comment_ID ); ?>
<div class="comment-box">
<?php if ( $type == 'comment' ) { ?>
<div class="avatar-container">
<?php echo get_avatar( get_comment_author_email(), 60 ); ?>
</div>
<?php } ?>
<div class="comment-container">
<div class="info">
<span class="author"><?php comment_author_link(); ?></span><span class="date"><?php comment_date(); ?></span>
</div>
<div class="comment-content content">
<?php if ( ! $comment->comment_approved ) { ?>
<p class="comment-awaiting-moderation">
<?php esc_html_e( 'Your comment is awaiting moderation.', 'siteorigin-corp' ); ?>
</p>
<?php } ?>
<?php comment_text(); ?>
</div>
<?php if ( $depth <= $args['max_depth'] ) { ?>
<?php comment_reply_link( array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ); ?>
<?php } ?>
</div>
</div>
<?php
}
}
if ( ! function_exists( 'siteorigin_corp_display_logo' ) ) {
/**
* Display the logo or site title.
*/
function siteorigin_corp_display_logo() {
do_action( 'siteorigin_corp_logo_before' );
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
the_custom_logo();
} else {
$tag = is_front_page() ? 'h1' : 'p';
?>
<<?php echo $tag; ?> class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<?php bloginfo( 'name' ); ?>
</a>
</<?php echo $tag; ?>>
<?php
}
do_action( 'siteorigin_corp_logo_after' );
}
}
/**
* Add the retina srcset to the custom logo attributes.
*/
function siteorigin_corp_display_retina_logo( $attr, $attachment ) {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$retina = siteorigin_setting( 'header_retina_logo' );
if ( ! empty( $retina ) && ! empty( $custom_logo_id ) && $attachment->ID == $custom_logo_id ) {
$srcset = empty( $attr['srcset'] ) ? array() : explode( ',', $attr['srcset'] );
$retina_src = wp_get_attachment_image_src( $retina, 'full' );
if ( ! empty( $retina_src ) ) {
$srcset[] = $retina_src[0] . ' 2x';
}
if ( ! empty( $srcset ) ) {
$attr['srcset'] = implode( ',', $srcset );
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'siteorigin_corp_display_retina_logo', 10, 2 );
if ( ! function_exists( 'siteorigin_corp_display_icon' ) ) {
/**
* Displays SVG icons.
*/
function siteorigin_corp_display_icon( $type ) {
switch ( $type ) {
case 'cart': ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16.97" height="16" viewBox="0 0 16.97 16">
<path id="cart" class="cls-1" d="M1313.9,36.289l-2.01,6a0.994,0.994,0,0,1-.95.711h-7.35a0.962,0.962,0,0,1-.35-0.072c-0.04-.015-0.07-0.037-0.11-0.056a0.969,0.969,0,0,1-.19-0.131,0.644,0.644,0,0,1-.1-0.1c-0.04-.056-0.08-0.117-0.12-0.184-0.02-.043-0.04-0.084-0.06-0.13-0.01-.024-0.02-0.043-0.03-0.068l-2.09-7.07A1.779,1.779,0,0,0,1298.98,34h-0.99a1,1,0,0,1,0-2h0.99a3.773,3.773,0,0,1,3.49,2.669l0.1,0.332h10.38a1,1,0,0,1,.8.4A0.969,0.969,0,0,1,1313.9,36.289Zm-10.74.71,1.18,4h5.85l1.41-4h-8.44Zm0.81,7a2,2,0,1,1-2,2A2,2,0,0,1,1303.97,44Zm6.99,0a2,2,0,1,1-2,2A2,2,0,0,1,1310.96,44Z" transform="translate(-1297 -32)"/>
</svg>
<?php break;
case 'close': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
<path d="M18.984 6.422l-5.578 5.578 5.578 5.578-1.406 1.406-5.578-5.578-5.578 5.578-1.406-1.406 5.578-5.578-5.578-5.578 1.406-1.406 5.578 5.578 5.578-5.578z"></path>
</svg>
<?php break;
case 'left-arrow': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="18" height="32" viewBox="0 0 18 32">
<path fill="#fff" d="M18.284 29.705l-2.284 2.285-15.99-15.99 15.99-15.99 2.284 2.285-13.705 13.705z"></path>
</svg>
<?php break;
case 'menu': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="27" height="32" viewBox="0 0 27 32">
<path d="M27.429 24v2.286q0 0.464-0.339 0.804t-0.804 0.339h-25.143q-0.464 0-0.804-0.339t-0.339-0.804v-2.286q0-0.464 0.339-0.804t0.804-0.339h25.143q0.464 0 0.804 0.339t0.339 0.804zM27.429 14.857v2.286q0 0.464-0.339 0.804t-0.804 0.339h-25.143q-0.464 0-0.804-0.339t-0.339-0.804v-2.286q0-0.464 0.339-0.804t0.804-0.339h25.143q0.464 0 0.804 0.339t0.339 0.804zM27.429 5.714v2.286q0 0.464-0.339 0.804t-0.804 0.339h-25.143q-0.464 0-0.804-0.339t-0.339-0.804v-2.286q0-0.464 0.339-0.804t0.804-0.339h25.143q0.464 0 0.804 0.339t0.339 0.804z"></path>
</svg>
<?php break;
case 'right-arrow': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="18" height="32" viewBox="0 0 18 32">
<path fill="#fff" d="M17.589 16l-15.402 15.989-2.2-2.283 13.202-13.706-13.202-13.706 2.2-2.283 13.202 13.704z"></path>
</svg>
<?php break;
case 'search': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="26" height="28" viewBox="0 0 26 28">
<path d="M18 13c0-3.859-3.141-7-7-7s-7 3.141-7 7 3.141 7 7 7 7-3.141 7-7zM26 26c0 1.094-0.906 2-2 2-0.531 0-1.047-0.219-1.406-0.594l-5.359-5.344c-1.828 1.266-4.016 1.937-6.234 1.937-6.078 0-11-4.922-11-11s4.922-11 11-11 11 4.922 11 11c0 2.219-0.672 4.406-1.937 6.234l5.359 5.359c0.359 0.359 0.578 0.875 0.578 1.406z"></path>
</svg>
<?php break;
case 'up-arrow': ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<path class="st0" d="M12,2c0.3,0,0.5,0.1,0.7,0.3l7,7C19.9,9.5,20,9.7,20,10c0,0.3-0.1,0.5-0.3,0.7S19.3,11,19,11
c-0.3,0-0.5-0.1-0.7-0.3L13,5.4V21c0,0.3-0.1,0.5-0.3,0.7S12.3,22,12,22s-0.5-0.1-0.7-0.3S11,21.3,11,21V5.4l-5.3,5.3
C5.5,10.9,5.3,11,5,11c-0.3,0-0.5-0.1-0.7-0.3C4.1,10.5,4,10.3,4,10c0-0.3,0.1-0.5,0.3-0.7l7-7C11.5,2.1,11.7,2,12,2z"/>
</svg>
<?php break;
}
}
}
if ( ! function_exists( 'siteorigin_corp_the_post_navigation' ) ) {
/**
* Display navigation to next/previous post when applicable.
*/
function siteorigin_corp_the_post_navigation() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
$previous_post = get_previous_post();
if ( ! empty( $previous_post ) ) {
$previous_thumb = get_the_post_thumbnail( $previous_post->ID, 'thumbnail' );
}
$next_post = get_next_post();
if ( ! empty( $next_post ) ) {
$next_thumb = get_the_post_thumbnail( $next_post->ID, 'thumbnail' );
}
?>
<nav class="navigation post-navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'siteorigin-corp' ); ?></h2>
<div class="nav-links">
<?php if ( ! empty( $previous_post ) ) { ?>
<div class="nav-previous">
<?php previous_post_link( '%link', ' ' . $previous_thumb . '<div class="nav-innner"><span>' . esc_html__( 'Previous Post', 'siteorigin-corp' ) . '</span> <div>%title</div></div>' ); ?>
</div>
<?php } ?>
<?php if ( ! empty( $next_post ) ) { ?>
<div class="nav-next">
<?php next_post_link( '%link', '<div class="nav-innner"><span>' . esc_html__( 'Next Post', 'siteorigin-corp' ) . '</span> <div>%title</div></div>' . $next_thumb . ' ' ); ?>
</div>
<?php } ?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
}
if ( ! function_exists( 'siteorigin_corp_read_more_link' ) ) {
/**
* Filter the read more link.
*/
function siteorigin_corp_read_more_link() {
$read_more_text = esc_html__( 'Continue reading', 'siteorigin-corp' );
return '<a class="more-link" href="' . esc_url( get_permalink() ) . '"><span class="more-text">' . $read_more_text . ' <span class="icon-long-arrow-right"></span></span></a>';
}
}
add_filter( 'the_content_more_link', 'siteorigin_corp_read_more_link' );
if ( ! function_exists( 'siteorigin_corp_excerpt_length' ) ) {
/**
* Filter the excerpt length.
*/
function siteorigin_corp_excerpt_length( $length ) {
return ! empty( siteorigin_setting( 'blog_excerpt_length' ) ) ? siteorigin_setting( 'blog_excerpt_length' ) : 55;
}
add_filter( 'excerpt_length', 'siteorigin_corp_excerpt_length', 10 );
}
if ( ! function_exists( 'siteorigin_corp_excerpt' ) ) {
/**
* Outputs the excerpt.
*/
function siteorigin_corp_excerpt() {
if ( ( siteorigin_setting( 'blog_archive_content' ) == 'excerpt' ) && siteorigin_setting( 'blog_post_excerpt_read_more_link', true ) && ! is_search() ) {
$read_more_text = esc_html__( 'Continue reading', 'siteorigin-corp' );
$read_more_text = '<a class="more-link excerpt" href="' . esc_url( get_permalink() ) . '"><span class="more-text">' . $read_more_text . ' <span class="icon-long-arrow-right"></span></span></a>';
} else {
$read_more_text = '';
}
if ( is_search() ) {
$length = 30;
} else {
$length = ! empty( siteorigin_setting( 'blog_excerpt_length' ) ) ? siteorigin_setting( 'blog_excerpt_length' ) : 55;
}
$excerpt = get_the_excerpt();
$excerpt_add_read_more = str_word_count( $excerpt ) >= $length;
if ( ! has_excerpt() ) {
$excerpt = wp_trim_words( $excerpt, $length, '...' );
}
if ( ! empty( $read_more_text ) && ( has_excerpt() || $excerpt_add_read_more ) ) {
$excerpt .= $read_more_text;
}
echo '<p>' . wp_kses_post( $excerpt ) . '</p>';
}
}
if ( ! function_exists( 'siteorigin_corp_entry_thumbnail_meta' ) ) {
/**
* Print HTML with meta information for the sticky status, current post-date/time, author, comment count and post categories.
*/
function siteorigin_corp_entry_thumbnail_meta() {
echo '<div class="thumbnail-meta">';
if ( has_category() ) {
echo get_the_category_list();
}
echo '</div>';
}
}
if ( ! function_exists( 'siteorigin_corp_offset_post_meta' ) ) {
/**
* Print HTML with meta information for the post author, categories and comment count for the offset blog layout.
*/
function siteorigin_corp_offset_post_meta() {
$num_comments = get_comments_number();
if ( comments_open() ) {
if ( $num_comments == 0 ) {
$comments = esc_html__( 'Post a Comment', 'siteorigin-corp' );
} elseif ( $num_comments > 1 ) {
$comments = $num_comments . esc_html__( ' Comments', 'siteorigin-corp' );
} else {
$comments = esc_html__( '1 Comment', 'siteorigin-corp' );
}
} else {
$comments = null;
} ?>
<div class="entry-author-avatar">
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 70 ); ?>
</a>
</div>
<div class="entry-author-link">
<span class="meta-text"><?php esc_html_e( 'Written by', 'siteorigin-corp' ); ?></span>
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
<?php echo get_the_author(); ?>
</a>
</div>
<?php if ( siteorigin_setting( 'blog_post_categories' ) ) { ?>
<div class="entry-categories">
<span class="meta-text"><?php esc_html_e( 'Posted in', 'siteorigin-corp' ); ?></span>
<?php the_category( ', ', '', '' ); ?>
</div>
<?php } ?>
<?php if ( $comments && siteorigin_setting( 'blog_post_comment_count' ) ) { ?>
<div class="entry-comments">
<span class="meta-text"><?php esc_html_e( 'Comments', 'siteorigin-corp' ); ?></span>
<a href="<?php get_comments_link(); ?>"><?php echo $comments; ?></a>
</div>
<?php }
}
}
if ( ! function_exists( 'siteorigin_corp_related_posts' ) ) {
/**
* Display related posts on single posts.
*/
function siteorigin_corp_related_posts( $post_id ) {
if ( function_exists( 'related_posts' ) ) { // Check for YARPP plugin (https://wordpress.org/plugins/yet-another-related-posts-plugin/).
related_posts();
} elseif ( class_exists( 'Jetpack' ) && class_exists( 'Jetpack_RelatedPosts' ) ) {
echo do_shortcode( '[jetpack-related-posts]' );
} else { // The fallback loop.
$categories = get_the_category( $post_id );
if ( empty( $categories ) ) {
return;
}
$first_cat = $categories[0]->cat_ID;
$args = array(
'category__in' => array( $first_cat ),
'post__not_in' => array( $post_id ),
'posts_per_page' => 3,
'ignore_sticky_posts' => -1,
);
$related_posts = new WP_Query( $args ); ?>
<div class="related-posts-section">
<h3 class="related-posts"><?php esc_html_e( 'Related Posts', 'siteorigin-corp' ); ?></h3>
<?php if ( $related_posts->have_posts() ) { ?>
<ol>
<?php while ( $related_posts->have_posts() ) {
$related_posts->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'siteorigin-corp-720x480-crop' ); ?>
<div class="corp-content-wrapper">
<h3 class="related-post-title"><?php the_title(); ?></h3>
<p class="related-post-date"><?php echo get_the_date(); ?></p>
</div>
</a>
</li>
<?php } ?>
</ol>
<?php } else { ?>
<br /><p><?php esc_html_e( 'No related posts.', 'siteorigin-corp' ); ?></p>
<?php } ?>
</div>
<?php wp_reset_query();
}
}
}
if ( ! function_exists( 'siteorigin_corp_related_projects' ) ) {
/**
* Displays related posts in single projects.
*/
function siteorigin_corp_related_projects( $post_id ) {
if ( class_exists( 'Jetpack' ) && class_exists( 'Jetpack_RelatedPosts' ) ) {
echo do_shortcode( '[jetpack-related-posts]' );
} else { // The fallback loop.
$categories = get_the_terms( $post_id, 'jetpack-portfolio-type' );
if ( is_array( $categories ) ) {
$first_cat = $categories[0]->term_id;
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'jetpack-portfolio-type',
'field' => 'term_id',
'terms' => $first_cat,
),
),
'post__not_in' => array( $post_id ),
'posts_per_page' => 3,
'ignore_sticky_posts' => -1,
);
$related_posts = new WP_Query( $args ); ?>
<div class="related-projects-section">
<h3><?php esc_html_e( 'Related Posts', 'siteorigin-corp' ); ?></h2>
<?php if ( $related_posts->have_posts() ) { ?>
<div class="related-projects">
<?php if ( $related_posts->have_posts() ) { ?>
<?php while ( $related_posts->have_posts() ) {
$related_posts->the_post(); ?>
<?php get_template_part( 'template-parts/content', 'portfolio' ); ?>
<?php } ?>
<?php } ?>
</div>
<?php } else { ?>
<p><?php esc_html_e( 'No related projects.', 'siteorigin-corp' ); ?></p>
<?php } ?>
</div>
<?php
wp_reset_query();
}
}
}
}
if ( ! function_exists( 'siteorigin_corp_tag_cloud' ) ) {
/**
* Filter the Tag Cloud widget.
*/
function siteorigin_corp_tag_cloud( $args ) {
$args['unit'] = 'px';
$args['largest'] = 12;
$args['smallest'] = 12;
return $args;
}
}
add_filter( 'widget_tag_cloud_args', 'siteorigin_corp_tag_cloud' );
if ( ! function_exists( 'siteorigin_corp_post_meta' ) ) {
/**
* Print HTML with meta information for the sticky status, current post-date/time, author, post categories and comment count.
*/
function siteorigin_corp_post_meta( $cats = true, $post_id = '', $echo = true ) {
$output = '';
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'siteorigin-corp' ) );
$cats = apply_filters( 'siteorigin_corp_display_categories', $cats );
if ( is_sticky() && ! is_paged() ) {
$output .= '<span class="featured-post">' . esc_html__( 'Sticky', 'siteorigin-corp' ) . '</span>';
}
if ( ( is_home() || is_archive() || is_search() ) && siteorigin_setting( 'blog_post_date' ) ) {
$output .= '<span class="entry-date"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark"><time class="published" datetime="' . esc_attr( get_the_date( 'c' ) ) . '">' . esc_html( get_the_date() ) . '</time><time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></a></span>';
}
if ( is_single() && siteorigin_setting( 'blog_post_date' ) ) {
$output .= '<span class="entry-date"><time class="published" datetime="' . esc_attr( get_the_date( 'c' ) ) . '">' . esc_html( get_the_date() ) . '</time><time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>';
}
if ( siteorigin_setting( 'blog_post_author' ) ) {
$output .= '<span class="byline"><span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" rel="author">' . esc_html( get_the_author() ) . '</a></span></span>';
}
if ( siteorigin_setting( 'blog_post_categories' ) ) {
if ( 'jetpack-portfolio' == get_post_type() ) {
$portfolio_terms = get_the_term_list( $post_id, 'jetpack-portfolio-type', '', ', ', '' );
if ( $portfolio_terms ) {
$output .= sprintf( '<span class="entry-category">' . '%1$s' . '</span>', $portfolio_terms );
}
} else {
if ( $categories_list && $cats == true ) {
$output .= sprintf( '<span class="entry-category">' . '%1$s' . '</span>', $categories_list ); // WPCS: XSS OK.
}
}
}
if ( comments_open() && siteorigin_setting( 'blog_post_comment_count' ) ) {
$output .= '<span class="comments-link">';
ob_start();
comments_popup_link( esc_html__( 'Leave a comment', 'siteorigin-corp' ), esc_html__( 'One Comment', 'siteorigin-corp' ), esc_html__( '% Comments', 'siteorigin-corp' ) );
$output .= ob_get_clean();
$output .= '</span>';
}
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
}
if ( ! function_exists( 'siteorigin_corp_posted_on' ) ) {
/**
* Prints HTML with meta information for the current post-date/time.
*/
function siteorigin_corp_posted_on( $echo = true ) {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf(
$time_string,
esc_attr( get_the_date( DATE_W3C ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( DATE_W3C ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
/* translators: %s: post date. */
esc_html_x( 'Posted on %s', 'post date', 'siteorigin-corp' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$output = '<span class="posted-on">' . $posted_on . '</span>'; // WPCS: XSS OK.
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
}
if ( ! function_exists( 'siteorigin_corp_entry_footer' ) ) {
/**
* Print HTML with meta information for the post tags.
*/
function siteorigin_corp_entry_footer( $post_id = '' ) {
if ( is_single() && has_tag() && siteorigin_setting( 'blog_post_tags' ) ) {
echo '<footer class="entry-footer"><span class="tags-links">' . get_the_tag_list() . '</span></footer>';
}
$portfolio_terms = get_the_term_list( $post_id, 'jetpack-portfolio-tag', '', '', '' );
if ( 'jetpack-portfolio' == get_post_type() && $portfolio_terms ) {
printf( '<footer class="entry-footer"><span class="tags-links">' . '%1$s' . '</span></footer>', $portfolio_terms );
}
}
}
if ( ! function_exists( 'siteorigin_corp_footer_text' ) ) {
/**
* Insert footer text from theme settings.
*/
function siteorigin_corp_footer_text() {
$text = siteorigin_setting( 'footer_text' );
if ( empty( $text ) ) {
return;
}
$text = str_replace(
array( '{sitename}', '{year}' ),
array( get_bloginfo( 'sitename' ), date( 'Y' ) ),
'<span>' . $text . '</span>'
);
echo wp_kses_post( $text );
}
}
/**
* Add a filter for Jetpack Featured Content.
*/
function siteorigin_corp_get_featured_posts() {
return apply_filters( 'siteorigin_corp_get_featured_posts', array() );
}
/**
* Check the Jetpack Featured Content.
*/
function siteorigin_corp_has_featured_posts( $minimum = 1 ) {
if ( is_paged() ) {
return false;
}
$minimum = absint( $minimum );
$featured_posts = apply_filters( 'siteorigin_corp_get_featured_posts', array() );
if ( ! is_array( $featured_posts ) ) {
return false;
}
if ( $minimum > count( $featured_posts ) ) {
return false;
}
return true;
}
if ( ! function_exists( 'siteorigin_corp_display_featured_posts' ) ) {
/**
* Output the Jetpack Featured Content.
*/
function siteorigin_corp_display_featured_posts() {
if ( is_home() && siteorigin_corp_has_featured_posts() ) {
get_template_part( 'template-parts/featured', 'slider' );
}
}
}
add_action( 'siteorigin_corp_content_before', 'siteorigin_corp_display_featured_posts' );
if ( ! function_exists( 'siteorigin_corp_strip_gallery' ) ) {
/**
* Remove gallery.
*/
function siteorigin_corp_strip_gallery( $content ) {
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( 'gallery' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ( false !== $pos ) {
return substr_replace( $content, '', $pos, strlen( $shortcode[0] ) );
}
}
}
}
return $content;
}
}
if ( ! function_exists( 'siteorigin_corp_get_gallery' ) ) {
/**
* Get gallery from content for gallery format posts.
*/
function siteorigin_corp_get_gallery() {
$gallery = get_post_gallery( get_the_ID(), false );
if ( ! empty( $gallery ) && ! has_action( 'wp_footer', 'siteorigin_corp_enqueue_flexslider' ) ) {
add_action( 'wp_footer', 'siteorigin_corp_enqueue_flexslider' );
}
return ( '' !== $gallery ) ? $gallery : false;
}
}
if ( ! function_exists( 'siteorigin_corp_get_video' ) ) {
/**
* Get the video from the current post.
*/
function siteorigin_corp_get_video() {
$first_url = '';
$first_video = '';
$i = 0;
preg_match_all( '|^\s*https?://[^\s"]+\s*$|im', get_the_content(), $urls );
foreach ( $urls[0] as $url ) {
$i++;
if ( 1 === $i ) {
$first_url = trim( $url );
}
$oembed = wp_oembed_get( esc_url( $url ) );
if ( ! $oembed ) {
continue;
}
$first_video = $oembed;
break;
}
wp_enqueue_script( 'jquery-fitvids' );
return ( '' !== $first_video ) ? $first_video : false;
}
}
if ( ! function_exists( 'siteorigin_corp_filter_video' ) ) {
/**
* Removes the video from the page.
*/
function siteorigin_corp_filter_video( $content ) {
if ( siteorigin_corp_get_video() ) {
preg_match_all( '|^\s*https?://[^\s"]+\s*$|im', $content, $urls );
if ( ! empty( $urls[0] ) ) {
$content = str_replace( $urls[0][0], '', $content );
}
return $content;
} else {
return $content;
}
}
}
if ( ! function_exists( 'siteorigin_corp_get_image' ) ) {
/**
* Removes the first image from the page.
*/
function siteorigin_corp_get_image() {
preg_match_all( '/<img[^>]+\>/i', get_the_content(), $images );
if ( empty( $images[0] ) ) {
return false;
}
$first_image = $images[0][0];
return ( '' !== $first_image ) ? $first_image : false;
}
}
if ( ! function_exists( 'siteorigin_corp_strip_image' ) ) {
/**
* Removes the first image from the page.
*/
function siteorigin_corp_strip_image( $content ) {
return preg_replace( '/<img[^>]+\>/i', '', $content, 1 );
}
}
if ( ! function_exists( 'siteorigin_corp_is_post_loop_widget' ) ) {
/**
* Checks if we're currently rendering a post loop widget.
*/
function siteorigin_corp_is_post_loop_widget() {
return method_exists( 'SiteOrigin_Panels_Widgets_PostLoop', 'is_rendering_loop' ) && SiteOrigin_Panels_Widgets_PostLoop::is_rendering_loop();
}
}
if ( ! function_exists( 'siteorigin_corp_is_post_loop_template' ) ) {
/**
* Check if we're currently rendering a specific Page Builder Post Loop widget template.
*
* @return bool
*/
function siteorigin_corp_is_post_loop_template( $check ) {
if ( ! method_exists( 'SiteOrigin_Panels_Widgets_PostLoop', 'get_current_loop_template' ) ) {
return false;
}
switch( $check ) {
case 'offset':
return SiteOrigin_Panels_Widgets_PostLoop::get_current_loop_template() == 'loops/loop-blog-offset.php';
case 'grid':
return SiteOrigin_Panels_Widgets_PostLoop::get_current_loop_template() == 'loops/loop-blog-grid.php';
case 'alternate':
return SiteOrigin_Panels_Widgets_PostLoop::get_current_loop_template() == 'loops/loop-blog-alternate.php';
case 'masonry':
return SiteOrigin_Panels_Widgets_PostLoop::get_current_loop_template() == 'loops/loop-blog-masonry.php';
}
return false;
}
}
if ( ! function_exists( 'siteorigin_corp_entry_thumbnail' ) ) {
/**
* Displays the entry thumbnail for all blog loops.
*/
function siteorigin_corp_entry_thumbnail() {
if ( is_single() ) {
if ( siteorigin_setting( 'blog_post_featured_image' ) ) { ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php }
} elseif (
(
! siteorigin_corp_is_post_loop_widget() &&
siteorigin_setting( 'blog_archive_featured_image' ) &&
siteorigin_setting( 'blog_archive_layout' ) == 'grid'
) ||
siteorigin_corp_is_post_loop_template( 'grid' )
) {
?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'siteorigin-corp-720x480-crop' ); ?>
</a>
</div>
<?php
} elseif (
(
! siteorigin_corp_is_post_loop_widget() &&
siteorigin_setting( 'blog_archive_featured_image' ) &&
siteorigin_setting( 'blog_archive_layout' ) == 'alternate'
) ||
siteorigin_corp_is_post_loop_template( 'alternate' )
) {
?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'siteorigin-corp-720x480-crop' ); ?>
</a>
</div>
<?php
} elseif (
(
! siteorigin_corp_is_post_loop_widget() &&
siteorigin_setting( 'blog_archive_featured_image' ) &&
siteorigin_setting( 'blog_archive_layout' ) == 'masonry'
)
|| siteorigin_corp_is_post_loop_template( 'masonry' )
) {
?>
<div class="entry-thumbnail">
<?php
if ( siteorigin_setting( 'blog_post_categories' ) ) {
siteorigin_corp_entry_thumbnail_meta();
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php
} elseif ( siteorigin_setting( 'blog_archive_featured_image' ) ) {
?>
<div class="entry-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php
}
}
}
if ( ! function_exists( 'siteorigin_corp_get_post_title' ) ) {
/**
* Displays the current post title.
*/
function siteorigin_corp_get_post_title() {
if ( ! empty( get_the_title() ) ) {
if ( is_single() ) {
if ( siteorigin_page_setting( 'page_title' ) ) {
return '<h1 class="entry-title">' . get_the_title() . '</h1>';
}
} else {
return '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . get_the_title() . '</a></h2>';
}
}
}
}