forked from oldmill1/jquery-image-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQueryImageCarousel.php
100 lines (86 loc) · 2.41 KB
/
jQueryImageCarousel.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
Plugin Name: jQuery Image Carousel for WordPress
Plugin URI:
Description: Use shortcodes in your posts to display multiple images in a carousel.
Version: 1.0.0
Author: Ankur Taxali
Author URI: https://github.com/oldmill1
License: GPL2
*/
wp_enqueue_script("jquery"); // load jQuery for those who don't have it
wp_enqueue_script(
'jic',
plugins_url( 'js/jic.js', __FILE__ ),
NULL,
NULL,
TRUE
);
wp_enqueue_script(
'jqueryui',
plugins_url( 'js/jquery-ui.min.js', __FILE__ ),
NULL,
NULL,
TRUE
);
wp_enqueue_style(
'jic-styles',
plugins_url( 'css/style.css', __FILE__ )
);
//[carousel size="medium"]
function carousel_func( $atts ){
extract( shortcode_atts( array(
'size' => 'medium',
'effect' => 'none'
), $atts ) );
$postID = get_the_id();
$num = -1;
$sizes = array("thumbnail", "medium", "large", "full");
if ( ! in_array( $size, $sizes ) ) {
$size = "medium";
}
$effects = array("blind", "bounce", "clip", "drop", "explode", "fold", "highlight", "puff", "pulsate", "scale", "shake", "size", "slide");
if ( ! in_array( $effect, $effects ) ) {
$effect = "none";
}
$images = get_children(
array(
'post_parent' => $postID,
'post_type' => 'attachment',
'numberposts' => $num,
'order' => 'ASC',
'orderby' => 'ID',
'post_mime_type' => 'image'
)
);
if ( !empty( $images ) ) {
// we've got some images !
foreach ( $images as $image ) {
$attachmenturl = wp_get_attachment_url($image->ID);
$attachmentthumbsrc = wp_get_attachment_image_src( $image->ID, $size );
$img_title = $image->post_title;
$imagelocs[] = array(
"full" => $attachmenturl,
"thumb" => $attachmentthumbsrc[0],
"title" => $img_title,
"width" => $attachmentthumbsrc[1],
"height" => $attachmentthumbsrc[2]
);
}
}
$build = "<div id='jquery_image_carousel' ";
if ( $effect != "none" ) {
$build .= " class='jic-effect-{$effect}'";
}
$build .= ">";
$build .= "<ul>";
foreach ( $imagelocs as $imageloc ) {
$build .= "<li><img src='{$imageloc['full']}' width='{$imageloc['width']}' height='{$imageloc['height']}' /><div class='caption'><h6>{$imageloc['title']}</h6></div></li>";
}
$build .= "</ul>";
$build .= "<a href='#' class='jic_nav jic_previous'>Previous</a>";
$build .= "<a href='#' class='jic_nav jic_next'>Next</a>";
$build .= "</div>";
return $build;
}
add_shortcode( 'carousel', 'carousel_func' );