Answer the question
In order to leave comments, you need to log in
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();?>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question