示例#1
0
function wpsight_image_slider($atts)
{
    $defaults = array('link' => '', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => get_the_ID(), 'size' => 'big', 'include' => '', 'exclude' => '', 'prevnext' => 'true', 'keynav' => 'false', 'mousenav' => 'false', 'effect' => 'fade', 'direction' => 'horizontal', 'timer' => 0);
    extract(shortcode_atts($defaults, $atts));
    if (!empty($include)) {
        $include = preg_replace('/[^0-9,]+/', '', $include);
        $args = array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby);
        $args = apply_filters('wpsight_image_slider_args', $args);
        $_attachments = get_posts($args);
        $attachments = array();
        foreach ($_attachments as $k => $v) {
            $attachments[$v->ID] = $_attachments[$k];
        }
    } else {
        if ($exclude == 'featured') {
            $exclude = get_post_thumbnail_id(get_the_ID());
        }
        $exclude = preg_replace('/[^0-9,]+/', '', $exclude);
        $args = array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby);
        $args = apply_filters('wpsight_image_slider_args', $args);
        $attachments = get_children($args);
    }
    // Stop if no attachments
    if (empty($attachments)) {
        return;
    }
    // Return attachment link list in feeds
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $att_id => $attachment) {
            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        }
        return $output;
    }
    // Get layout
    $layout = get_post_meta(get_the_ID(), '_layout', true);
    $post_type = get_post_type();
    // Check full size
    $full_size = $layout == 'full-width' || !is_active_sidebar('sidebar') && !is_active_sidebar('sidebar-' . $post_type) ? true : false;
    // Correct image size
    $size = $full_size == true && $size == 'big' ? 'full' : $size;
    // Correct image size
    $size = $size == 'small' ? 'post-thumbnail' : $size;
    // Correct span depending on image size
    $span = $size == 'post-thumbnail' ? 'small' : $size;
    // Correct timer and slideshow = true
    $slideshow = $timer == 0 ? 'false' : 'true';
    // Correct timer
    $timer = $timer != 0 ? $timer . '000' : 0;
    $slider_args = array('animation' => '"' . $effect . '",', 'direction' => '"' . $direction . '",', 'slideshow' => "{$slideshow},", 'slideshowSpeed' => "{$timer},", 'animationDuration' => '300,', 'directionNav' => "{$prevnext},", 'controlNav' => 'false,', 'keyboardNav' => "{$keynav},", 'mousewheel' => "{$mousenav},", 'prevText' => '"' . __('Previous', 'wpsight') . '",', 'nextText' => '"' . __('Next', 'wpsight') . '",', 'pausePlay' => 'false,', 'pauseText' => '"' . __('Pause', 'wpsight') . '",', 'playText' => '"' . __('Play', 'wpsight') . '",', 'animationLoop' => 'true,', 'pauseOnAction' => 'true,', 'pauseOnHover' => 'true');
    $slider_args = apply_filters('wpsight_image_slider_options_args', $slider_args);
    // Create inline slider Javascript
    $output = "\n" . '<script type="text/javascript">' . "\n";
    $output .= 'jQuery(document).ready(function($){' . "\n";
    $output .= "\t" . '$(function(){' . "\n";
    $output .= "\t\t" . '$(".flexslider").flexslider({' . "\n";
    foreach ($slider_args as $k => $v) {
        $output .= "\t\t\t" . $k . ': ' . $v . "\n";
    }
    $output .= "\t\t" . '});' . "\n";
    $output .= "\t" . '});' . "\n";
    $output .= '});' . "\n";
    $output .= '</script>' . "\n\n";
    /**
     * Set fixed height on slider container
     * to avoid layout jump on load
     */
    $img = wpsight_get_image_size($size);
    $height = $img['size']['h'];
    $output .= '<div class="row"><div class="image-slider ' . wpsight_get_span($span) . '">' . "\n";
    $output .= "\n\t" . '<div class="flexslider height-' . $height . '"><ul class="slides">' . "\n";
    // Loop through attachments
    foreach ($attachments as $attachment_id => $attachment) {
        $output .= "\n\t\t" . '<li>';
        // Link to attachment page
        if ($link == 'attachment') {
            $output .= wp_get_attachment_link($attachment_id, $size, true, false);
        } else {
            // Unlinked image
            $image = wp_get_attachment_image($attachment_id, $size);
            // Link image if desired
            if ($link != 'false') {
                $src = wp_get_attachment_image_src($attachment_id, apply_filters('wpsight_post_slider_lightbox_size', 'original'));
                $output .= '<a href="' . $src[0] . '" title="' . $attachment->post_title . '" class="gallery-link">' . $image . '</a>';
            } else {
                $output .= $image;
            }
        }
        $output .= '</li>' . "\n";
    }
    $output .= "\n\t" . '</ul></div><!-- .flexslider -->' . "\n";
    $output .= "\n" . '</div><!-- .image-slider --></div>' . "\n";
    return apply_filters('wpsight_image_slider_shortcode', $output, $atts);
}
示例#2
0
    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        $title = isset($instance['title']) ? apply_filters('widget_title', strip_tags($instance['title']), $instance, $this->id_base) : false;
        $filter = isset($instance['filter']) ? strip_tags($instance['filter']) : false;
        $effect = isset($instance['effect']) ? $instance['effect'] : 'fade';
        $direction = isset($instance['direction']) ? $instance['direction'] : 'horizontal';
        $timer = isset($instance['timer']) ? (int) $instance['timer'] : 0;
        $prevnext = isset($instance['prevnext']) ? $instance['prevnext'] : true;
        $overlay = isset($instance['overlay']) ? $instance['overlay'] : true;
        $details = isset($instance['details']) ? $instance['details'] : true;
        $teaser = isset($instance['teaser']) ? $instance['teaser'] : true;
        $keynav = isset($instance['keynav']) ? $instance['keynav'] : true;
        $mousenav = isset($instance['mousenav']) ? $instance['mousenav'] : false;
        $random = isset($instance['random']) ? $instance['random'] : false;
        $unlink = isset($instance['unlink']) ? $instance['unlink'] : false;
        $number = isset($instance['number']) ? (int) $instance['number'] : 10;
        $length = isset($instance['length']) ? (int) $instance['length'] : 15;
        /**
         * Only show slider on first page
         * if blog template on front page
         */
        global $page;
        if (isset($page) && $page != 1) {
            return;
        }
        // Create query args
        if ($filter != 'custom') {
            $query_args = array('post_type' => array(wpsight_listing_post_type()), 'posts_per_page' => $number);
            // Add filter to query args if required
            if (!empty($filter)) {
                if ($filter == 'latest-sale') {
                    // Set meta_query
                    $meta_query = array(array('key' => '_price_status', 'value' => 'sale'));
                    $query_args = array_merge($query_args, array('meta_query' => $meta_query));
                } elseif ($filter == 'latest-rent') {
                    // Set meta_query
                    $meta_query = array(array('key' => '_price_status', 'value' => 'rent'));
                    $query_args = array_merge($query_args, array('meta_query' => $meta_query));
                } elseif ($filter == 'latest-new') {
                    // Set meta_query
                    $meta_query = array(array('key' => '_price_status', 'value' => 'new'));
                    $query_args = array_merge($query_args, array('meta_query' => $meta_query));
                } elseif ($filter == 'latest-used') {
                    // Set meta_query
                    $meta_query = array(array('key' => '_price_status', 'value' => 'used'));
                    $query_args = array_merge($query_args, array('meta_query' => $meta_query));
                } else {
                    // Get taxonomy and term from filter (comma-separated value)
                    $get_taxonomy = explode(',', $filter);
                    $taxonomy = $get_taxonomy[0];
                    $term = $get_taxonomy[1];
                    // Set tax_query
                    $tax_query = array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => array($term)));
                    $query_args = array_merge($query_args, array('tax_query' => $tax_query));
                }
            }
        } else {
            // If filter is custom, create meta query (slider => 1)
            $query_args = array('post_type' => array(wpsight_listing_post_type()), 'posts_per_page' => $number, 'meta_query' => array(array('key' => 'slider', 'value' => '1')));
        }
        // Add random order to query args if required
        if ($random == true) {
            $query_args = array_merge($query_args, array('orderby' => 'random'));
        }
        $query_args = apply_filters('wpsight_widget_slider_query_args', $query_args, $args, $instance);
        // Check if transients are active
        $transients = apply_filters('wpsight_transients_queries', false, 'widget', $query_args, $this->id);
        // If query transients are active
        if ($transients === true) {
            // If transient does not exist
            if (false === ($slider = get_transient('wpsight_query_' . $this->id))) {
                // Create listing query
                $slider = new WP_Query($query_args);
                // Set transient for this query
                set_transient('wpsight_query_' . $this->id, $slider, DAY_IN_SECONDS);
            }
            // If query transients are not active
        } else {
            // Create listing query
            $slider = new WP_Query($query_args);
        }
        if ($slider->have_posts()) {
            // Create loop counter
            $counter = 1;
            // Set image size depending on widget area
            if ($id == 'home') {
                $image_size = 'big';
            } elseif ($id == 'sidebar' || $id == 'sidebar-home' || $id == 'sidebar-archive' || $id == 'sidebar-page' || $id == 'sidebar-post' || $id == wpsight_get_sidebar('sidebar-listing') || $id == wpsight_get_sidebar('sidebar-listing-archive')) {
                $image_size = 'post-thumbnail';
            } else {
                $image_size = 'full';
            }
            $image_size = apply_filters('wpsight_widget_listings_slider_image_size', $image_size, $args, $instance);
            // Create widget output
            ?>
			
			<div id="<?php 
            echo wpsight_dashes($this->id);
            ?>
" class="widget widget-slider widget-listings-slider clearfix">
			
				<div class="widget-inner">
        	
        			<?php 
            // Display widget title
            if (!empty($title)) {
                ?>
							
						<div class="title title-widget clearfix">
					
						    <?php 
                echo apply_filters('wpsight_widget_listings_slider_title', '<h2>' . $title . '</h2>', $args, $instance);
                do_action('wpsight_widget_listings_slider_title_actions', $args, $instance);
                ?>
						
						</div><?php 
            }
            // endif $title
            // Convert boolean to strings for Javascript options
            $prevnext = $prevnext == true ? 'true' : 'false';
            $keynav = $keynav == true ? 'true' : 'false';
            $mousenav = $mousenav == true ? 'true' : 'false';
            $random = $random == true ? 'true' : 'false';
            // Correct timer and slideshow = true
            $slideshow = $timer == 0 ? 'false' : 'true';
            $slider_args = array('animation' => '"' . $effect . '",', 'direction' => '"' . $direction . '",', 'slideshow' => "{$slideshow},", 'slideshowSpeed' => "{$timer},", 'animationDuration' => '300,', 'directionNav' => "{$prevnext},", 'controlNav' => 'false,', 'keyboardNav' => "{$keynav},", 'mousewheel' => "{$mousenav},", 'prevText' => '"' . __('Previous', 'wpsight') . '",', 'nextText' => '"' . __('Next', 'wpsight') . '",', 'pausePlay' => 'false,', 'pauseText' => '"' . __('Pause', 'wpsight') . '",', 'playText' => '"' . __('Play', 'wpsight') . '",', 'randomize' => "{$random},", 'animationLoop' => 'true,', 'pauseOnAction' => 'true,', 'pauseOnHover' => 'true');
            $slider_args = apply_filters('wpsight_widget_listings_slider_options_args', $slider_args, $args, $instance);
            ?>
					
					<script type="text/javascript">
					jQuery(document).ready(function($){
					    $(function(){
					    	$('.flexslider').flexslider({
					    		<?php 
            foreach ($slider_args as $k => $v) {
                echo $k . ': ' . $v . "\n";
            }
            ?>
							});
					    });	            
					});
					</script>
					
					<?php 
            /**
             * Set fixed height on slider container
             * to avoid layout jump on load
             */
            $img = wpsight_get_image_size($image_size);
            $height = $img['size']['h'];
            ?>
        			
        			<div class="flexslider height-<?php 
            echo $height;
            ?>
">
        			
					  	<ul class="slides">
					  	
					  		<?php 
            // Loop through posts
            while ($slider->have_posts()) {
                $slider->the_post();
                // Check if slider_embed is active
                $slider_embed = get_post_meta(get_the_ID(), 'slider_embed', true);
                if (!empty($slider_embed)) {
                    echo '<li>' . wp_kses_post($slider_embed) . '</li>';
                } elseif (has_post_thumbnail()) {
                    ?>
					  				
					  				<li>
					  					<?php 
                    if ($unlink == false) {
                        echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_ID(), $image_size, array('alt' => get_the_title(), 'title' => get_the_title())) . '</a>';
                    } else {
                        echo get_the_post_thumbnail(get_the_ID(), $image_size, array('alt' => get_the_title(), 'title' => get_the_title()));
                    }
                    if ($overlay == true) {
                        ?>
					  						<div class="overlay<?php 
                        if ($teaser == false) {
                            echo ' no-teaser';
                        }
                        ?>
">
					  							<?php 
                        // Action hook to add content before overlay title
                        do_action('wpsight_widget_listings_slider_title_before', $args, $instance);
                        ?>
					  							<h3>
					  								<?php 
                        if ($unlink == false) {
                            echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                        } else {
                            echo get_the_title();
                        }
                        ?>
					  							</h3>
					  							<?php 
                        // Action hook to add content after overlay title
                        do_action('wpsight_widget_listings_slider_title_after', $args, $instance);
                        if ($teaser == true) {
                            if ($unlink == false) {
                                wpsight_the_excerpt(get_the_ID(), true, $length);
                            } else {
                                echo wpsight_format_content(get_the_content(false));
                            }
                            // Action hook to add content after overlay teaser
                            do_action('wpsight_widget_listings_slider_teaser_after', $args, $instance);
                        }
                        ?>
					  						</div>
					  					<?php 
                    }
                    ?>
					  				</li>
					  				
					  				<?php 
                }
                // endif has_post_thumbnail()
            }
            // endwhile have_posts()
            ?>
					  	</ul>
					  	
					</div><!-- .flexslider -->
				
				</div><!-- .widget-inner -->
				
			</div><!-- .widget-slider --><?php 
        }
        // endif have_posts()
    }
示例#3
0
?>
	
	<div id="main-middle" class="row">
	
		<?php 
// Set class of #content div depending on active sidebars
$content_class = is_active_sidebar('sidebar-post') || is_active_sidebar('sidebar') ? wpsight_get_span('big') : wpsight_get_span('full');
$args = array('full-width' => apply_filters('wpsight_attachment_full_width', false), 'image_lightbox' => true);
$args = apply_filters('wpsight_attachment_image_args', $args);
// Set class depending on individual page layout
if ($args['full-width'] == true) {
    $content_class = wpsight_get_span('full');
}
// Set image max size depending on active sidebars
$image_big = wpsight_get_image_size('big');
$image_full = wpsight_get_image_size('full');
$image_max = $content_class == wpsight_get_span('full') ? $image_full['size']['w'] : $image_big['size']['w'];
?>
	
	    <div id="content" class="<?php 
echo $content_class;
?>
">
	    
	    	<?php 
if (wp_attachment_is_image(get_the_ID())) {
    $att_image = wp_get_attachment_image_src(get_the_ID(), array($image_max, $image_max));
    ?>
					
				
					<div class="post post-attachment">