shortcodes-resources.php
5.95 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
<?php
add_shortcode('resources-list', 'resources_list');
function resources_list($atts){
$atts['tax'];
try{
$custom_args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'paged' => 1,
'post_status' => 'any',
'order' => 'DESC',
'orderby' => 'rand',
'tax_query' => array(
array (
'taxonomy' => 'mlo-category',
'field' => 'id',
'terms' => $atts['tax'],
)
),
);
$custom_query = new \WP_Query($custom_args);
ob_start();
$uniqid = uniqid();
if ($custom_query->have_posts()):
?>
<div class="course-list resources">
<label for="quicksearch">Search:</label><input type="text" id="quicksearch" placeholder="" />
<div class="filters">
<a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-down"></span></a>
<div class="filter-group open">
<div class="category-filter-group ">
<div class="category">
<?php $terms = get_terms( array( 'taxonomy' => 'mlo-category' ,'parent' => $atts['tax']) );
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>
<div class="btn-group sort-button-group">
<button class="btn btn-light" data-sort-direction="asc" data-sort-value="0" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
<button class="btn btn-light" data-sort-direction="asc" data-sort-value="2" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
</div>
</div>
</div>
</div>
<table id="resources">
<thead><tr><th class="hidden"></th><th></th><th class="hidden"></th><th></th></tr></thead>
<tbody>
<?php while ($custom_query->have_posts()): $custom_query->the_post();
echo resources(get_the_ID(), $atts['tax']);
endwhile; ?>
</tbody>
</table>
</div>
<div class="modal fade flag-modal" id="flagModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="exampleModalLabel">Flag Document</h3>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?php echo do_shortcode('[ninja_form id=3]'); ?>
</div>
</div>
</div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("resources_list()". $e->getMessage()) ;
}
}
add_shortcode('resources-fav', 'resources_fav');
function resources_fav(){
$favorites = get_user_favorites(get_current_user_id());
ob_start();
$uniqid = uniqid();
if (is_array( $favorites)): ?>
<div class="course-list resources">
<table id="resources" class="resources-fav">
<thead><tr><th class="hidden"></th><th class="hidden"></th><th></th><th class="hidden"></th><th></th></tr></thead>
<tbody>
<?php foreach($favorites as $fav){
echo resources($fav);
}; ?>
</tbody>
</table>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}
function resources($id, $tax){
ob_start();
$post = get_post($id);
$text = str_replace(']]>', ']]>', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
$excerpt_length = apply_filters( 'excerpt_length', 20 );
$text = wp_trim_words( $text, $excerpt_length, ' ...' );
$categories = get_the_terms( $id, 'mlo-category' );
$cat ="";
if(is_array( $categories)){
foreach( $categories as $category ) {
if($category->parent == $tax){
$cat .= " ".$category->slug;
}
};
} ?>
<tr class="table-like__item">
<td class="item">
<a target="_blank" role="button" class="item-link" href="<?php echo wp_get_attachment_url($id); ?>"><?php echo $post->post_title; ?></a>
</td>
<td class="hidden"> <?php echo $cat; ?></td>
<td class="hidden"><?php echo get_post_time('U',false, $id ); ?></td>
<td class="wide-td">
<a target="_blank" role="button" href="<?php echo wp_get_attachment_url($id); ?>" class="button">View</a>
<a type="button" data-title="<?php echo $post->post_title; ?>" class="flag" data-bs-toggle="modal" data-bs-target="#flagModal"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-flag-fill" viewBox="0 0 16 16">
<path d="M14.778.085A.5.5 0 0 1 15 .5V8a.5.5 0 0 1-.314.464L14.5 8l.186.464-.003.001-.006.003-.023.009a12.435 12.435 0 0 1-.397.15c-.264.095-.631.223-1.047.35-.816.252-1.879.523-2.71.523-.847 0-1.548-.28-2.158-.525l-.028-.01C7.68 8.71 7.14 8.5 6.5 8.5c-.7 0-1.638.23-2.437.477A19.626 19.626 0 0 0 3 9.342V15.5a.5.5 0 0 1-1 0V.5a.5.5 0 0 1 1 0v.282c.226-.079.496-.17.79-.26C4.606.272 5.67 0 6.5 0c.84 0 1.524.277 2.121.519l.043.018C9.286.788 9.828 1 10.5 1c.7 0 1.638-.23 2.437-.477a19.587 19.587 0 0 0 1.349-.476l.019-.007.004-.002h.001"/>
</svg></a>
</td>
</tr>
<?php
$output = ob_get_clean();
return $output;
}