Answer the question
In order to leave comments, you need to log in
How to display different images on a slider?
steamchenin.com Can
you please tell me how to display different images on the slider? Multiple images have been uploaded to WP, but only the latest one by upload date is displayed.
<?php
//Вывод записей
$args = array(
'post_type' => 'slider',
'posts_per_page' => -1
);
$slider = new WP_Query( $args );
?>
<?php if( $slider->have_posts() ) : while ( $slider->have_posts() ) : $slider->the_post(); ?>
<!-- Записи -->
<div id="slider" class="owl-carousel owl-theme">
<div >
<img src="<?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ); echo $large_image_url[0]; ?>" alt="<?php the_title(); ?>">
</div>
<div>
<img src="<?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ); echo $large_image_url[0]; ?>" alt="<?php the_title(); ?>">
</div>
<div>
<img src="<?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ); echo $large_image_url[0]; ?>" alt="<?php the_title(); ?>">
</div>
<div>
<img src="<?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ); echo $large_image_url[0]; ?>" alt="<?php the_title(); ?>">
</div>
</div>
<?php endwhile; else: ?>
<h3>Картинок нет</h3>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
In your code, the same picture is displayed - a thumbnail attached to the post.
link to images like this:
<img src="<?php bloginfo('template_directory'); ?>/assets/img/slider/pic1.jpg">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/slider/pic2.jpg">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/slider/pic3.jpg">
You are using WordPress Loop incorrectly. Try like this:
<?php
// Получение записей
$args = array(
'post_type' => 'slider',
'posts_per_page' => -1
);
$slider = new WP_Query( $args );
// Вывод результатов
if( $slider->have_posts() ) :
?>
<!-- Записи -->
<div id="slider" class="owl-carousel owl-theme">
<?php
// Цикл!
while ( $slider->have_posts() ) : $slider->the_post();
?>
<div>
<img src="<?php the_post_thumbnail_url( 'medium' ); ?>" alt="<?php the_title(); ?>">
</div>
<?php
// Конец цикла
endwhile;
?>
</div>
<!-- Записи закончились -->
<?php
// Если записи не были обнаружены
else:
?>
<h3>Картинок нет</h3>
<?php endif; ?>
Thanks for the help and the loop structure, managed to solve it through MultiPostThumbnails
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question