ajayver

Untitled

Sep 3rd, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.60 KB | None | 0 0
  1. add_action( 'after_setup_theme', 'replace_simple_slider', 20 );
  2.  
  3. function replace_simple_slider() {
  4.     remove_shortcode('vc_simple_slider');
  5.     add_shortcode('vc_simple_slider', 'my_simple_slider');
  6. }
  7.  
  8. function my_simple_slider($attributes) {
  9.     $post = get_post();
  10.  
  11.     static $instance = 0;
  12.     $instance++;
  13.  
  14.     if ( ! empty( $attributes['ids'] ) )
  15.     {
  16.         // 'ids' is explicitly ordered, unless you specify otherwise.
  17.         if ( empty( $attributes['orderby'] ) )
  18.         {
  19.             $attributes['orderby'] = 'post__in';
  20.         }
  21.         $attributes['include'] = $attributes['ids'];
  22.     }
  23.  
  24.     // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  25.     if ( isset( $attributes['orderby'] ) )
  26.     {
  27.         $attributes['orderby'] = sanitize_sql_orderby( $attributes['orderby'] );
  28.         if ( !$attributes['orderby'] )
  29.         {
  30.             unset( $attributes['orderby'] );
  31.         }
  32.     }
  33.  
  34.     extract(shortcode_atts(array(
  35.         'order'      => 'ASC',
  36.         'orderby'    => 'menu_order ID',
  37.         'id'         => $post->ID,
  38.         'itemtag'    => 'dl',
  39.         'icontag'    => 'dt',
  40.         'captiontag' => 'dd',
  41.         'columns'    => 3,
  42.         'type'       => 's',
  43.         'include'    => '',
  44.         'exclude'    => '',
  45.         'auto_rotation'    => null,
  46.     ), $attributes));
  47.  
  48.     $type_classes = ' type_slider';
  49.     $size = 'gallery-full';
  50.  
  51.     $id = intval($id);
  52.  
  53.     if ( !empty($include) )
  54.     {
  55.         $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  56.  
  57.         $attachments = array();
  58.         if (is_array($_attachments))
  59.         {
  60.             foreach ( $_attachments as $key => $val ) {
  61.                 $attachments[$val->ID] = $_attachments[$key];
  62.             }
  63.         }
  64.     }
  65.     elseif ( !empty($exclude) )
  66.     {
  67.         $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  68.     }
  69.     else
  70.     {
  71.         $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  72.     }
  73.  
  74.     if ( empty($attachments) )
  75.     {
  76.         return '';
  77.     }
  78.  
  79.     $rand_id = rand(100000, 999999);
  80.     $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.'">';
  81.  
  82.     $i = 1;
  83.     if (is_array($attachments))
  84.     {
  85.  
  86.         $output .= '<ul class="slides">';
  87.         foreach ( $attachments as $id => $attachment ) {
  88.  
  89.             $output .= '<li>';
  90.             $output .= wp_get_attachment_image( $id, $size, 0 );
  91.             $output .= '</li>';
  92.  
  93.             $i++;
  94.  
  95.         }
  96.         $output .= '</ul>';
  97.  
  98.     }
  99.  
  100.     $output .= "</div></div></div>\n";
  101.  
  102.     $disable_rotation = '';
  103.     if ( ! ($auto_rotation == 'yes' OR $auto_rotation == 1)) {
  104.         $disable_rotation = 'slideshow: false,';
  105.     }
  106.  
  107.     $output .= '<script type="text/javascript">
  108.                    jQuery(window).load(function() {
  109.                        jQuery("#slider_'.$rand_id.'").flexslider({
  110.                            '.$disable_rotation.'controlsContainer: "#slider_'.$rand_id.'",
  111.                            directionalNav: true,
  112.                            controlNav: true,
  113.                            start: function(slider) {
  114.                                slider.resize();
  115.                                jQuery("#slider_'.$rand_id.'").removeClass("flex-loading");
  116.                            }
  117.                        });
  118.                    });
  119.                </script>';
  120.    $output .=  '<style>
  121.                 .flexslider {
  122.                     overflow: visible;
  123.                     margin-bottom: 30px;
  124.                 }
  125.                .g-html ol.flex-control-nav {
  126.                    width: 100%;
  127.                    position: absolute;
  128.                    bottom: -42px;
  129.                    text-align: center;
  130.                    margin: 0;
  131.                }
  132.  
  133.                .flex-control-nav li {
  134.                    margin: 0 6px;
  135.                    display: inline-block;
  136.                    zoom: 1;
  137.                }
  138.  
  139.                .flex-control-paging li a {
  140.                    width: 11px;
  141.                    height: 11px;
  142.                    display: block;
  143.                    background: rgba(127,127,127,0.5);
  144.                    cursor: pointer;
  145.                    text-indent: -9999px;
  146.                    -webkit-border-radius: 20px;
  147.                    -moz-border-radius: 20px;
  148.                    -o-border-radius: 20px;
  149.                    border-radius: 20px;
  150.                    -webkit-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
  151.                    -moz-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
  152.                    -o-box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
  153.                    box-shadow: inset 0 0 3px rgba(127,127,127,0.3);
  154.                }
  155.  
  156.                .flex-control-paging li a:hover {
  157.                    background: rgba(127,127,127,0.7);
  158.                }
  159.  
  160.                .flex-control-paging li a.flex-active {
  161.                    background: rgba(127,127,127,0.9);
  162.                    cursor: default;
  163.                }
  164.  
  165.                .no-touch .g-html li a:hover {
  166.                    border-bottom: none;
  167.                }</style>';
  168.  
  169.     return $output;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment