shortcodes-resources.php
3.83 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
<?php
add_shortcode('resources-list', 'resources_list');
function resources_list(){
$custom_args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'paged' => 1,
'post_status' => 'any',
'order' => 'DESC',
'orderby' => 'ID',
);
$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 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 ">
<div class="category">
<?php $terms = get_terms( array( 'taxonomy' => 'media-category' ,'parent' => 17) );
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="type">
<?php $terms = get_terms( array( 'taxonomy' => 'media-category' ,'parent' => 22) );
foreach($terms as $term){ ?>
<div class="category-type"> <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 align-self-end">
<button class="btn btn-light" data-sort-direction="asc" data-sort-value="1" 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="3" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button>
</div>
</div>
</div>
<table id="resources">
<thead><tr><th class="hidden"></th><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());
endwhile; ?>
</tbody>
</table>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}
function resources($id){
ob_start();
$post = get_post($id);
$categories = get_the_terms( $id, 'media-category' );
$cat ="";
$type ="";
if(is_array( $categories)){
foreach( $categories as $category ) {
if($category->parent == 17){
$cat .= " ".$category->slug;
}
if($category->parent == 22){
$type .= " ".$category->slug;
}
};
} ?>
<tr class="table-like__item">
<td class="hidden"> <?php echo $type; ?></td>
<td class="item <?php echo $type; ?>"><div class="item-content"><a role="button" href="<?php echo get_permalink($id); ?>"><?php echo $post->post_title; ?></a><br>
<?php echo wp_get_attachment_caption($id) ?><div>
</td>
<td class="hidden"> <?php echo $cat; ?></td>
<td class="hidden"><?php echo get_post_time('U',false, $id ); ?></td>
<td><?php echo do_shortcode('[favorite_button post_id="'.$id.'"]'); ?></td>
</tr>
<?php
$output = ob_get_clean();
return $output;
}