Last active
December 15, 2015 03:29
-
-
Save sagarjadhav/5194245 to your computer and use it in GitHub Desktop.
Convert Gallery into Cycle Slideshow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Gallery Shortcode */ | |
function gallery_to_slideshow($atts) { | |
global $post; | |
$slider_html = ''; | |
$ids = NULL; | |
$image_size = NULL; | |
extract( shortcode_atts( array( 'ids' => '', 'image_size' => 'thumbnail' ), $atts) ); | |
$attachment_ids = explode(',', $ids); | |
if ( isset( $attachment_ids ) && !empty( $attachment_ids ) ) { | |
$slider_html .= '<div class="rtp-slideshow-container">'; | |
//$slider_html .='<a href="#" class="rtp-close">'. __('Close', 'rtPanel') .'</a>'; | |
$slider_html .= '<ul class="cycle-slideshow rtp-main-slideshow" | |
data-cycle-slides="> li" | |
data-cycle-timeout="4000" | |
data-cycle-log="false" | |
data-cycle-prev=".cycle-prev" | |
data-cycle-next=".cycle-next" | |
data-cycle-fx="fade"> '; | |
foreach ( $attachment_ids as $attachment_id ) { | |
$attachment = get_post($attachment_id); | |
$slide = wp_get_attachment_image_src($attachment_id, $image_size); | |
$slider_html .= '<li class="slide">'; | |
$slider_html .='<img src="' . $slide[0] .'" alt="' . $attachment->post_title . '" />'; | |
$slider_html .= '<h2 class="attachment-title">' . $attachment->post_title . '</h2>'; | |
$slider_html.='<div class="image-description">' . $attachment->post_content. '</div>'; | |
$slider_html.='</li>'; | |
} | |
$slider_html .= '</ul>'; | |
$slider_html .= '<div class="rtp-prev cycle-prev">'. __('<<Prev', 'rtPanel') .'</div>'; | |
$slider_html .= '<div class="rtp-next cycle-next">'. __('Next>>', 'rtPanel') .'</div>'; | |
$slider_html .= '</div>';//End of Div rtp-slideshow-container | |
return $slider_html; | |
} | |
} | |
/* Override Gallery */ | |
remove_shortcode('gallery'); | |
add_shortcode('gallery', 'gallery_to_slideshow'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: You must use cycle2 jQuery plugin for slideshow. (http://www.malsup.com/jquery/cycle2/download/)