~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
<?php
// Get posts
$args = array();
$args['post_type'] = 'downloads';
if (!empty($search)) {
	$args['s'] = $search;
}
$query = new WP_Query($args);
?>
<ul class="loop-results search-downloads 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); ?>" width="66" height="66" title="<?php echo $attachment->post_excerpt; ?>" alt="<?php echo $attachment->post_excerpt; ?>" />
		    <?php else : ?>
		    	<?php if (has_post_thumbnail()) :
		    		echo the_post_thumbnail(array(66, 66), array('alt' => '', 'title' => ''));
		    	else : ?>
		    		<img src="<?php echo get_template_directory_uri(); ?>/img/icon-file-generic.png" width="66" height="66" 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>