~barry-mcgee/ubuntu-brand-guidelines/search-tidyup-proper

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
<?php
// Get posts
$args = array();
$args['post_type'] = 'downloads';
$args['posts_per_page'] = 100;
$metadata = get_query_var('metadata');
$search = get_search_query();
if (!empty($metadata)) {
	$args['metadata'] = $metadata;
}
if (!empty($search)) {
	$args['metadata'] = ''; // Overwrite metadata
	$args['s'] = $search;
}
$query = new WP_Query($args);
?>
<div id="loop-status" class="clearfix">
	<p><span><?php echo $query->post_count; ?> result<?php if ($query->post_count != 1) : ?>s<?php endif; ?></span><?php if (!empty($search)) : ?> | Your search: <?php endif; ?></p>
</div>
<ul class="loop-results clearfix">
<?php
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
// Get post attachments
$args = array();
$args['post_type'] = 'attachment';
$args['post_parent'] = $post->ID;
$attachments = get_posts($args);
foreach ($attachments as $attachment) :
if ($attachment->ID != get_post_thumbnail_id($post->ID)) :
?>
	<li>
		<a href="<?php echo wp_get_attachment_url($attachment->ID, false); ?>"<?php $terms = (wp_get_post_terms($post->ID, 'metadata')); foreach ($terms as $term) : if ($term->slug == 'colour-white') : echo ' class="colour-white"'; endif; endforeach; ?>>
			<?php if (preg_match('/image/i', $attachment->post_mime_type)) : ?>
				<img src="<?php echo wp_get_attachment_thumb_url($attachment->ID); ?>" title="<?php echo $attachment->post_excerpt; ?>" alt="<?php echo $attachment->post_excerpt; ?>" />
			<?php else : ?>
				<?php if (has_post_thumbnail()) :
					echo the_post_thumbnail('thumbnail', array('alt' => '', 'title' => ''));
				else : ?>
					<img src="<?php echo get_template_directory_uri(); ?>/img/icon-file-generic.png" width="140" height="140" title="<?php echo $attachment->post_excerpt; ?>" alt="<?php echo $attachment->post_excerpt; ?>" />
				<?php endif; ?>
			<?php endif; ?>
		</a>
		<?php echo $attachment->post_excerpt; ?><br/>
		<a href="<?php echo wp_get_attachment_url($attachment->ID, false); ?>">
			Download <?php echo getPostAttachmentExtension($attachment->post_mime_type) . ' (' . getPostAttachmentFilesize(get_attached_file($attachment->ID)) . ')'; ?>
		</a>
	</li>
<?php
endif;
endforeach;
endwhile;
else :
?>
	<li class="loop-error">Sorry, no results have been found</li>
<?php
endif;
?>
</ul>