Skip to content

Commit 49b7e41

Browse files
committed
media cat/tag / single view and grid view
1 parent 4156b4c commit 49b7e41

7 files changed

+124
-5
lines changed

theme/attachment.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<div class="container">
2+
<?php get_template_part('templates/page', 'header'); ?>
3+
<div class="entry">
4+
<div class="entry-inner">
5+
6+
7+
<p class='resolutions'> Downloads:
8+
<?php
9+
$images = array();
10+
$image_sizes = get_intermediate_image_sizes();
11+
array_unshift( $image_sizes, 'full' );
12+
13+
$c = '';
14+
foreach( $image_sizes as $image_size ) {
15+
16+
$image = wp_get_attachment_image_src( get_the_ID(), $image_size );
17+
$name = $image_size . ' (' . $image[1] . 'x' . $image[2] . ')';
18+
$images[] = '<a href="' . $image[0] . '">' . $name . '</a>';
19+
20+
if($image_size == 'thumbnail'){
21+
$c = $image[0];
22+
23+
}
24+
}
25+
echo '<img src="'.$c.'" />';
26+
echo implode( ' | ', $images );
27+
28+
29+
30+
?>
31+
32+
</p>
33+
<?php get_template_part('templates/entry-taxonomies'); ?>
34+
35+
</div>
36+
<div class="clear"></div>
37+
</div><!--/.entry-->
38+
</div>

theme/lib/nuitdebout/utils.php

+8
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ function getAttachmentThumb($id) {
2121
$url = wp_get_attachment_image_src($thumb , [330, 180])[0];
2222
return $url;
2323
}
24+
function attachment_search( $query ) {
25+
if ( $query->is_search ) {
26+
$query->set( 'post_type', array( 'post', 'attachment' ) );
27+
$query->set( 'post_status', array( 'publish', 'inherit' ) );
28+
}
29+
return $query;
30+
}
31+
add_filter( 'pre_get_posts', 'attachment_search' );

theme/mediasquery.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Template Name: page media query
4+
* @package WordPress
5+
* @subpackage Twenty_Fourteen
6+
* @since Twenty Fourteen 1.0
7+
*/
8+
$args = array(
9+
'post_type' => 'attachment',
10+
'post_status' => 'any'
11+
);
12+
$the_query = new WP_Query( $args );
13+
if ( $the_query->have_posts() ) {
14+
while ( $the_query->have_posts() ) {
15+
$the_query->the_post();
16+
get_template_part('templates/entry-taxonomies');
17+
echo wp_get_attachment_image( get_the_ID(), 'thumbnail' );
18+
}
19+
} else {
20+
// no attachments found
21+
}
22+
wp_reset_postdata();

theme/taxonomy-media_category.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="container">
2+
<?php get_template_part('templates/page', 'header'); ?>
3+
4+
5+
<?php while (have_posts()) : the_post(); ?>
6+
<article <?php post_class(); ?>>
7+
<header>
8+
<?php
9+
$attachment_id = get_post_thumbnail_id();
10+
$attachment_page = get_attachment_link( $attachment_id );
11+
?>
12+
<a href="<?php echo $attachment_page; ?>"><?php the_title() ?></a>
13+
</header>
14+
<div class="entry-summary">
15+
<?php the_content(); ?>
16+
<?php get_template_part('templates/entry-taxonomies'); ?>
17+
</div>
18+
</article>
19+
<hr/>
20+
<?php endwhile; ?>
21+
22+
<?php the_posts_navigation(); ?>
23+
</div>

theme/taxonomy-media_tag.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="container">
2+
<?php get_template_part('templates/page', 'header'); ?>
3+
4+
5+
<?php while (have_posts()) : the_post(); ?>
6+
<article <?php post_class(); ?>>
7+
<header>
8+
<?php
9+
$attachment_id = get_post_thumbnail_id();
10+
$attachment_page = get_attachment_link( $attachment_id );
11+
?>
12+
<a href="<?php echo $attachment_page; ?>"><?php the_title() ?></a>
13+
</header>
14+
<div class="entry-summary">
15+
<?php the_content(); ?>
16+
<?php get_template_part('templates/entry-taxonomies'); ?>
17+
</div>
18+
</article>
19+
<hr/>
20+
<?php endwhile; ?>
21+
22+
<?php the_posts_navigation(); ?>
23+
</div>

theme/templates/content-search.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<article <?php post_class(); ?>>
22
<header>
3+
<?php if (get_post_type() === 'attachment') {
4+
echo 'Media:';
5+
}
6+
?>
7+
38
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
49
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
510
</header>
611
<div class="entry-summary">
7-
<?php the_excerpt(); ?>
12+
<?php //the_excerpt(); ?>
813
</div>
914
</article>

theme/templates/entry-taxonomies.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
$taxonomies = [];
3-
$types = array('category', 'post_tag','media_category');
3+
$types = array('category','media_category', 'post_tag','media_tag');
44
foreach( $types as $tax ) {
55
$categories = get_the_terms( $post->ID, $tax );
66
if($categories){
@@ -13,17 +13,17 @@
1313
<div class="post-taxonomies">
1414
<?php foreach( $taxonomies as $tax => $categories ) : ?>
1515
<span class="post-taxonomy post-taxonomy--<?php echo $tax ?>">
16-
<?php if($tax == 'category'): ?>
16+
<?php if($tax == 'category' || $tax == 'media_category'): ?>
1717
<span>Classé dans </span>
1818
<?php endif; ?>
19-
<?php if($tax == 'post_tag'): ?>
19+
<?php if($tax == 'post_tag' || $tax == 'media_tag'): ?>
2020
<span> | </span>
2121
<?php endif; ?>
2222
<?php foreach( $categories as $category ) : ?>
2323
<a href="<?php echo esc_url( get_category_link( $category->term_id ) )?>">
2424
<?php echo esc_html( $category->name ) ?>
2525
</a>
26-
<?php if($tax =='category' && $category !== end($categories)) : ?>,<?php endif; ?>
26+
<?php if(($tax =='category' || $tax =='media_category') && $category !== end($categories)) : ?>,<?php endif; ?>
2727
<?php endforeach ?>
2828
</span>
2929
<?php endforeach; ?>

0 commit comments

Comments
 (0)