shortcodes-course.php
5 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
<?php
add_shortcode('course-list', 'course_list');
function course_list(){
try{
$custom_args = array(
'post_type' => 'sfwd-courses',
'posts_per_page' => -1,
'paged' => 1,
);
$custom_query = new \WP_Query($custom_args);
ob_start();
$uniqid = uniqid();
if ($custom_query->have_posts()):?>
<div class="course-list">
<label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" />
<div class="filters">
<a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
<div class="filter-group">
<div class="category-filter-group">
<?php $terms = get_terms( array( 'taxonomy' => 'ld_course_category' ,'parent' => 0) );
foreach($terms as $term){ ?>
<div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
<?php }; ?>
</div>
<div class="btn-group sort-button-group">
<label>SORT BY:</label>
<button class="btn btn-light atoz" data-sort-direction="asc" data-sort-value="1" type="button"><spam class="text">A to Z</span></button>
<button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
</div>
</div>
</div>
<div class="grid course">
<?php while ($custom_query->have_posts()): $custom_query->the_post();
echo course_card(get_the_ID());
endwhile; ?>
</div>
</div>
<div id="noResultsContainer">
<div>No results match this search.</div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("course_list()". $e->getMessage()) ;
}
}
add_shortcode('my-course-list', 'my_course_list');
function my_course_list(){
ob_start();
$enrolled_courses = learndash_user_get_enrolled_courses(get_current_user_id()); ?>
<?php if (is_array($enrolled_courses) && !empty($enrolled_courses)): ?>
<div class="carousel course">
<div id="<?php echo $uniqid; ?>" class="course-carousel carousel-items container">
<div class='swiper-wrapper'>
<?php foreach($enrolled_courses as $enrolled){
echo course_card($enrolled);
}; ?>
</div>
<div class="swiper-pagination"></div>
</div>
<div class="swiper-button-prev" data-id="<?= $uniqid; ?>"></div>
<div class="swiper-button-next" data-id="<?= $uniqid; ?>"></div>
</div>
<?php else: ?>
<p class="empty-message" >You haven't enrolled in or completed any programs yet. When you have, they will be saved here.</p>
<?php endif; ?>
<style>
.paginate_button.disabled{
display: none;
}
</style>
<?php wp_reset_query();
$output = ob_get_clean();
return $output;
}
function course_card($id){
ob_start();
$post = get_post($id);
$text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
$text = str_replace('Program Overview', '', $text);
$excerpt_length = apply_filters( 'excerpt_length', 20 );
$text = wp_trim_words( $text, $excerpt_length, ' ...' );
$categories = get_the_terms( $id, 'ld_course_category' );
$cat =""; foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?>
<div data-name="<?php echo $post->post_name; ?>" data-ticks="<?php echo get_post_time('U',false, $id ); ?>" class="swiper-slide element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
<article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses">
<div class="card">
<div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div>
<div class="image">
<?php echo get_the_post_thumbnail($id, 'full' ); ?>
</div>
</div>
<div class="content">
<h3 class="entry-title"><?php echo $post->post_title; ?></h3>
<div class="entry-content">
<p><?php echo $text; ?></p>
</div>
<a class="btn" role="button" href="<?php echo get_permalink($id); ?>" rel="bookmark">LEARN MORE</a>
</div>
</div>
</article>
</div>
<?php
$output = ob_get_clean();
return $output;
}