A
A
Andrey Gladkov2016-05-18 22:17:19
Images
Andrey Gladkov, 2016-05-18 22:17:19

How to sort wordpress media files?

Good time of day to everyone) Tell me
people, I killed all day and couldn’t find an answer
. Here I have a WP media library with a bunch of photos, hung a heading "forest" on some images (for example) - I try to loop all the pictures for this heading, it doesn’t work (( ((He broke his whole head - how can you implement it - mb there is an easier way, but nothing comes to mind

<?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();?>

why do I need to
make a website for a tattoo studio, I want to dynamically display the latest works on the main page
as I imagine it
when loading media files, I assign the category "lastWork" to it with ID 21
and images are pulled up by this cycle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-05-20
@AlexGrRu

Everything is quite simple. You create a page/post to which pictures will be attached, in your case you need to attach images to your main page. Then you draw their conclusion:
1. display the shortcode on the page/post:
order - sorting method
orderby - by which parameter we sort by
type - type of displaying images
link - what link the image has
size - what size we display images
2. display images in the template:
options, enter what you need, as indicated above
3. display images in a loop:

<?php
    $gallery_shortcode = '[gallery ]';
    print apply_filters( 'the_content', $gallery_shortcode );
 ?>

we can also add options to the gallery output
. Subsequently, all attached images to the page will be added automatically.
Information taken from the PS Code
English and the WordPress Code are our everything :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question