M
M
minstrel77772020-11-27 15:31:46
Gallery
minstrel7777, 2020-11-27 15:31:46

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

3 answer(s)
V
Vladislav Chernenko, 2020-11-27
@vladchv

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;

Then collect all the attachments of the post in a bunch and display with a slider:
$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>';
}

PS: The 2nd code will only work for the pictures attached to this post , and not for those selected from those previously added to the gallery.

E
Eugene, 2020-11-27
@iamd503

Make up, connect the slider plugin and you will be happy.
https://owlcarousel2.github.io/OwlCarousel2/kenwheeler.github.io/slick
https://swiperjs.com/
_

M
minstrel7777, 2020-11-28
@minstrel7777

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 question

Ask a Question

731 491 924 answers to any question