Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'after_setup_theme', 'replace_simple_slider', 20 );
- function replace_simple_slider() {
- remove_shortcode('vc_simple_slider');
- add_shortcode('vc_simple_slider', 'my_simple_slider');
- }
- function my_simple_slider($attributes) {
- $post = get_post();
- static $instance = 0;
- $instance++;
- if ( ! empty( $attributes['ids'] ) )
- {
- // 'ids' is explicitly ordered, unless you specify otherwise.
- if ( empty( $attributes['orderby'] ) )
- {
- $attributes['orderby'] = 'post__in';
- }
- $attributes['include'] = $attributes['ids'];
- }
- // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
- if ( isset( $attributes['orderby'] ) )
- {
- $attributes['orderby'] = sanitize_sql_orderby( $attributes['orderby'] );
- if ( !$attributes['orderby'] )
- {
- unset( $attributes['orderby'] );
- }
- }
- extract(shortcode_atts(array(
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID',
- 'id' => $post->ID,
- 'itemtag' => 'dl',
- 'icontag' => 'dt',
- 'captiontag' => 'dd',
- 'columns' => 3,
- 'type' => 's',
- 'include' => '',
- 'exclude' => '',
- 'auto_rotation' => null,
- ), $attributes));
- $type_classes = ' type_slider';
- $size = 'gallery-full';
- $id = intval($id);
- if ( !empty($include) )
- {
- $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
- $attachments = array();
- if (is_array($_attachments))
- {
- foreach ( $_attachments as $key => $val ) {
- $attachments[$val->ID] = $_attachments[$key];
- }
- }
- }
- elseif ( !empty($exclude) )
- {
- $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
- }
- else
- {
- $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
- }
- if ( empty($attachments) )
- {
- return '';
- }
- $rand_id = rand(100000, 999999);
- $output = '<div class="w-gallery'.$type_classes.'"><div class="w-gallery-main"><div class="w-gallery-main-h flexslider flex-loading" id="slider_'.$rand_id.'">';
- $i = 1;
- if (is_array($attachments))
- {
- $output .= '<ul class="slides">';
- foreach ( $attachments as $id => $attachment ) {
- $output .= '<li>';
- $output .= wp_get_attachment_image( $id, $size, 0 );
- $output .= '</li>';
- $i++;
- }
- $output .= '</ul>';
- }
- $output .= "</div></div></div>\n";
- $disable_rotation = '';
- if ( ! ($auto_rotation == 'yes' OR $auto_rotation == 1)) {
- $disable_rotation = 'slideshow: false,';
- }
- $output .= '<script type="text/javascript">
- jQuery(window).load(function() {
- jQuery("#slider_'.$rand_id.'").flexslider({
- '.$disable_rotation.'controlsContainer: "#slider_'.$rand_id.'",
- directionalNav: true,
- controlNav: true,
- start: function(slider) {
- slider.resize();
- jQuery("#slider_'.$rand_id.'").removeClass("flex-loading");
- }
- });
- });
- </script>';
- $output .= '<style>
- .flexslider {
- overflow: visible;
- margin-bottom: 30px;
- }
- .g-html ol.flex-control-nav {
- width: 100%;
- position: absolute;
- bottom: -42px;
- text-align: center;
- margin: 0;
- }
- .flex-control-nav li {
- margin: 0 6px;
- display: inline-block;
- zoom: 1;
- }
- .flex-control-paging li a {
- width: 11px;
- height: 11px;
- display: block;
- background: rgba(127,127,127,0.5);
- cursor: pointer;
- text-indent: -9999px;
- -webkit-border-radius: 20px;
- -moz-border-radius: 20px;
- -o-border-radius: 20px;
- border-radius: 20px;
- -webkit-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
- -moz-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
- -o-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
- box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
- }
- .flex-control-paging li a:hover {
- background: rgba(127,127,127,0.7);
- }
- .flex-control-paging li a.flex-active {
- background: rgba(127,127,127,0.9);
- cursor: default;
- }
- .no-touch .g-html li a:hover {
- border-bottom: none;
- }</style>';
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment