How to filter Wordpress media files?

All of Dobrovol time of day)
People tell me all day killed could not find the answer
Now I have a media library of WP c a lot of pictures and hung on some images from the category "forest"(for example ) - try to deduce in a cycle all images on this category doesn't work(((( all head broke - how to implement a finally - MB there is an easier way,but the head did not go

<?php
$posts = get_posts( array('category'=-->21) );

foreach($posts as $post){ setup_postdata($post);?>

 <img class="postimg col-md-3" src="<?php echo $image ?>">
 <?php } wp_reset_postdata();?>


what you need
doing a site for a tattoo Studio,I want the main to do is dynamically output the last works
as I see it
when you download media files assigned to the category "lastWork" she ID 21
and the cycle of catch up images
July 9th 19 at 13:16
1 answer
July 9th 19 at 13:18
Everything is quite simple. Create a page/post to which you will attach the pictures in your case to attach images you need to your main page. Then make their conclusion

1. print shortcode in page/post:
[gallery order="ASC" orderby="ID" type="rectangular" link="file" size="medium"]

order - the sorting method
orderby - parameter by which sorted
type - the type of output images
link - what is the link to the image
size - how big output image


2. displaying images in the template:
<?php echo but this do_shortcode('[gallery option1="value1"]'); ?>

option type what is necessary, as stated above

3. displaying image in a loop:
<?php
 $gallery_shortcode = '[gallery ]';
 print apply_filters( 'the_content', $gallery_shortcode );
 ?>

you can also add options to the conclusion of the gallery

In consequence of all uploaded images in the page will be added automatically.
Information is taken from the Code

P. S. the English language and the WordPress Codex everything :)
thanks,not quite what I wanted-but got a couple of ideas - nikita.Stracke commented on July 9th 19 at 13:21

Find more questions by tags ImagesWordPress