shortcodes.php
5.17 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
<?php
add_shortcode( 'promos', 'promos' );
function promos(){
try{
$custom_args = array(
'post_type' => 'promo',
'posts_per_page' => 3,
'paged' => 1,
);
$custom_query = new \WP_Query($custom_args);
ob_start();
$uniqid = uniqid();
if ($custom_query->have_posts()):?>
<div class="carousel">
<div id="<?php echo $uniqid; ?>" class="promo-carousel carousel-items">
<div class='swiper-wrapper'>
<?php while ($custom_query->have_posts()): $custom_query->the_post();
echo promos_slides(get_the_ID());
endwhile; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev" data-id="<?= $uniqid; ?>"></div>
<div class="swiper-button-next" data-id="<?= $uniqid; ?>"></div>
</div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("promos()". $e->getMessage()) ;
}
}
function promos_slides($id){
ob_start();
$post = get_post($id);
$link = get_permalink($id);
if ($custom_link = get_post_meta($id, 'link', true)) {
$link = $custom_link;
}
$link_text = "Read More...";
if ($custom_link_text = get_post_meta($id, 'link_text', true)) {
$link_text = $custom_link_text;
}
$text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
$excerpt_length = apply_filters( 'excerpt_length', 40 );
$text = wp_trim_words( $text, $excerpt_length, ' ...' );?>
<div class="swiper-slide container">
<div class="promo row align-items-center">
<div class="col-lg-4 col-md-12">
<div class="promo-img">
<?php echo get_the_post_thumbnail($id, 'full' ); ?>
<div class="promo-img-over"> </div>
</div>
</div>
<div class="promo_content col-lg-8 col-md-12">
<?php echo '<h3>'.$post->post_title.'</h3><p>'. $text.'</p>'; ?>
<a class="promo-link" target="_blank" href="<?php echo $link; ?>" title="<?php the_title_attribute(); ?>"><?php echo $link_text;?></a>
</div>
</div>
</div>
<?php
$output = ob_get_clean();
return $output;
}
add_shortcode('share-this', 'share_this');
function share_this($atts){
$atts = shortcode_atts(array(
'post_id' => '',
), $atts, 'current-cover-articles');
$post = get_post($atts['post_id']);
ob_start();?>
<div class="custom-addtoany">
<div class="shareIcons" id="shareRoundIcons<?php echo $post->post_name; ?>"></div>
</div>
<script>
jQuery(document).ready(function ($) {
$("#shareRoundIcons<?php echo $post->post_name; ?>").jsSocials({
url: "<?php echo site_url() . '/' . $post->post_name; ?>",
text: ": <?php echo get_the_title($post->ID); ?>",
showLabel: false,
showCount: false,
shares: ["facebook", "twitter", "linkedin" ]
});
});
</script>
<?php
return ob_get_clean();
}
add_shortcode( 'firstname', 'firstname' );
function firstname(){
$user = get_userdata( get_current_user_id() );
return $user->first_name;;
}
add_shortcode( 'certs', 'certs' );
function certs(){
try{
$enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false);
ob_start();
if (is_array($enrolled_courses)):?>
<div class="carousel">
<div id="cert" class="cert-carousel carousel-items">
<div class='swiper-wrapper'>
<?php foreach($enrolled_courses as $enrolled_course){
$cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id());
if(!empty($cert)){
$sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true );
$thumbnail_id = "911"; ?>
<div class="swiper-slide container">
<div class="cert">
<?php echo '<a target="_blank" style="background-image:url('.wp_get_attachment_url( $thumbnail_id).')" class="cert_link" href="'.$cert.'"><p><strong>'
.get_user_meta(get_current_user_id(), 'first_name', true )." ". get_user_meta(get_current_user_id(), 'last_name', true ).'</strong></p>'
.get_the_title( $enrolled_course ).'</a>';
?>
</div>
</div>
<?php }
}; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev" data-id="cert"></div>
<div class="swiper-button-next" data-id="cert"></div>
</div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("certs()". $e->getMessage()) ;
}
}