-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslider.php
More file actions
executable file
·50 lines (43 loc) · 1.45 KB
/
Copy pathslider.php
File metadata and controls
executable file
·50 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
function get_images_from_media_library() {
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => 5,
'orderby' => 'rand'
);
$query_images = new WP_Query( $args );
$images = array();
foreach ( $query_images->posts as $image) {
// $images[]= $image->guid;
$attachments = wp_prepare_attachment_for_js($image->ID);
$obj =new \stdClass;
$obj->url = $attachments['caption'];
$obj->image = $attachments['url'];
$images[] = $obj;
}
return $images;
}
$sliders = get_images_from_media_library();
?>
<div class="swiper-container">
<div class="swiper-wrapper">
<?php foreach ($sliders as $key => $value) {
?>
<div class="swiper-slide">
<a href="<?php echo $value->url;?>" target="_blank">
<img src="<?php echo $value->image;?>">
</a>
</div>
<?php }?>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<?php if(!wp_is_mobile()){?>
<div class="swiper-button">
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<?php }?>
</div>