Answer the question
In order to leave comments, you need to log in
How to make slider for all images in wordpress article?
I have a WordPress site with a lot of posts with text and photos.
How can I automatically translate all the images in each post into a slider?
Now I have a text, after which there are pictures in a row, but I want to have 1 block after the text with a slider of all the images from this post.
Tell me please.
Answer the question
In order to leave comments, you need to log in
You can filter the_content by removing images from it:
$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", " ", $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
$attachments = get_posts(
array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
)
);
if ( $attachments ) {
echo '<div class="slider">';
foreach ( $attachments as $attachment ) {
$thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );
echo '<div class="slide">' . $thumbimg . '</div>';
}
echo '</div>';
}
Make up, connect the slider plugin and you will be happy.
https://owlcarousel2.github.io/OwlCarousel2/kenwheeler.github.io/slick
https://swiperjs.com/
_
There is such a solution: https://n-wp.ru/kak-vyivesti-vse-izobrazheniya-pos... , it displays a slider, but it doesn't work... it doesn't scroll...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question