forked from roots/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-files.php
86 lines (79 loc) · 2.86 KB
/
template-files.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
<?php
/*
Template Name: File Browser Template
*/
$tlc = get_post_meta($post->ID,'advedt_files_browse_category',true);
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
$map = array();
if ($attachments) {
foreach ($attachments as $post) {
$category = get_post_meta($post->ID, 'media_extensions_category', TRUE)?:null;
$state = get_post_meta($post->ID, 'media_extensions_folder', TRUE)?:null;
$subbox = get_post_meta($post->ID, 'media_extensions_subfolder', TRUE)?:"";
if ($tlc != "" && $tlc != $category) continue;
if ($state == null) continue;
if (!isset($map[$state])) $map[$state] = array();
if (!isset($map[$state][$subbox])) $map[$state][$subbox] = array();
$post->attachment_url = wp_get_attachment_url( $post->ID );
if (!in_array($post->ID,$map[$state][$subbox])) $map[$state][$subbox][] = $post;
}
}
ksort($map);
$hit = false;
foreach ($map as $aid => $child) : if ($aid === 'root' || $aid === '') continue; $hit = true; endforeach;
if (array_key_exists('National',$map)) {
$map = array('National' => $map['National']) + $map;
}
?>
<div class="container files-style">
<?php if ($hit) { ?>
<div class="row">
<div class="col-xs-12"><h2>State Pooled Trust Documents</h2></div>
</div>
<div class="row">
<div class="col-xs-10">
<?php foreach ($map as $aid => $child) : if ($aid === 'root' || $aid === '') continue; ?>
<a href="#" class="state-button" data-tab="<?php echo $aid; ?>"><?php echo $aid; ?></a>
<?php endforeach ?>
<div class="state-box" id="state-box">
</div>
</div>
</div>
<?php } ?>
<?php if (isset($map['root'])) { foreach ($map['root'] as $aid => $child) { ?>
<div class="row">
<div class="col-xs-12">
<h2><?php echo $aid; ?></h2>
<?php foreach ($map['root'][$aid] as $sid => $child) : ?>
<a class="document" href="<?php echo $child->attachment_url ?>"><?php echo "$child->post_title "; ?></a>
<?php endforeach ?>
</div>
</div>
<?php } } ?>
</div>
<script type="application/javascript">
data = <?php echo json_encode($map); ?>;
_$ = jQuery;
_$(function() {
_$('.state-button').click(function() {
_$('.state-button').removeClass('active');
_$(this).addClass('active');
_$('#state-box').html("");
var target = _$(this).data('tab');
for (var subdata in data[target]) {
_$('#state-box').append('<h3>' + subdata + '</h3>');
for (var file in data[target][subdata]) {
_$('#state-box').append('<a class="document" href="' + data[target][subdata][file]["attachment_url"] + '">' + data[target][subdata][file]["post_title"] + '</a>');
}
}
return false;
});
_$('.state-button').first().click();
});
</script>