示例#1
0
    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        extract(wp_parse_args($instance, $this->defaults));
        ?>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
"><?php 
        esc_html_e('Title', 'total');
        ?>
</label>
			<input class="widefat" name="<?php 
        echo esc_attr($this->get_field_name('title'));
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
		</p>

		<p>
		<label for="<?php 
        echo esc_attr($this->get_field_id('post_type'));
        ?>
"><?php 
        esc_html_e('Post Type', 'total');
        ?>
</label>
		<br />
		<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('post_type'));
        ?>
" style="width:100%;">
			<option value="post" <?php 
        if ($post_type == 'post') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        esc_html_e('Post', 'total');
        ?>
</option>
			<?php 
        // Get Post Types
        $args = array('public' => true, '_builtin' => false, 'exclude_from_search' => false);
        $output = 'names';
        $operator = 'and';
        $get_post_types = get_post_types($args, $output, $operator);
        if (!isset($get_post_types['portfolio']) && WPEX_PORTFOLIO_IS_ACTIVE) {
            $obj = get_post_type_object('portfolio');
            $get_post_types['portfolio'] = $obj->labels->name;
        }
        if (!isset($get_post_types['staff']) && WPEX_STAFF_IS_ACTIVE) {
            $obj = get_post_type_object('staff');
            $get_post_types['staff'] = $obj->labels->name;
        }
        if (!isset($get_post_types['testimonials']) && WPEX_TESTIMONIALS_IS_ACTIVE) {
            $obj = get_post_type_object('testimonials');
            $get_post_types['testimonials'] = $obj->labels->name;
        }
        foreach ($get_post_types as $get_post_type) {
            ?>
				<?php 
            if ($get_post_type != 'post') {
                ?>
					<option value="<?php 
                echo esc_attr($get_post_type);
                ?>
" <?php 
                selected($post_type, $get_post_type);
                ?>
>
						<?php 
                echo ucfirst(strip_tags($get_post_type));
                ?>
					</option>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
		</select>
		</p>

		<p>
		<label for="<?php 
        echo esc_attr($this->get_field_id('taxonomy'));
        ?>
"><?php 
        esc_html_e('Query By Taxonomy', 'total');
        ?>
</label>
		<br />
		<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('taxonomy'));
        ?>
" style="width:100%;">
			<option value="post" <?php 
        selected($taxonomy, '');
        ?>
><?php 
        esc_html_e('No', 'total');
        ?>
</option>
			<?php 
        // Get Taxonomies
        $get_taxonomies = get_taxonomies(array('public' => true), 'objects');
        ?>
			<?php 
        foreach ($get_taxonomies as $get_taxonomy) {
            ?>
				<option value="<?php 
            echo esc_attr($get_taxonomy->name);
            ?>
" <?php 
            if ($get_taxonomy->name == $taxonomy) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo ucfirst($get_taxonomy->labels->singular_name);
            ?>
</option>
			<?php 
        }
        ?>
		</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('terms'));
        ?>
"><?php 
        esc_html_e('Terms', 'total');
        ?>
</label>
			<br />
			<input class="widefat" name="<?php 
        echo esc_attr($this->get_field_name('terms'));
        ?>
" type="text" value="<?php 
        echo esc_attr($terms);
        ?>
" />
			<small><?php 
        esc_html_e('Enter the term slugs to query by seperated by a "comma"', 'total');
        ?>
</small>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('order'));
        ?>
"><?php 
        esc_html_e('Order', 'total');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('order'));
        ?>
">
				<option value="DESC" <?php 
        selected($order, 'DESC');
        ?>
><?php 
        esc_html_e('Descending', 'total');
        ?>
</option>
				<option value="ASC" <?php 
        selected($order, 'ASC');
        ?>
><?php 
        esc_html_e('Ascending', 'total');
        ?>
</option>
			</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('orderby'));
        ?>
"><?php 
        esc_html_e('Order By', 'total');
        ?>
:</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('orderby'));
        ?>
" id="<?php 
        echo esc_attr($this->get_field_id('orderby'));
        ?>
">
			<?php 
        // Orderby options
        $orderby_array = array('date' => esc_html__('Date', 'total'), 'title' => esc_html__('Title', 'total'), 'modified' => esc_html__('Modified', 'total'), 'author' => esc_html__('Author', 'total'), 'rand' => esc_html__('Random', 'total'), 'comment_count' => esc_html__('Comment Count', 'total'));
        foreach ($orderby_array as $key => $value) {
            ?>
				<option value="<?php 
            echo esc_attr($key);
            ?>
" <?php 
            selected($orderby, $key);
            ?>
>
					<?php 
            echo strip_tags($value);
            ?>
				</option>
			<?php 
        }
        ?>
			</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('number'));
        ?>
"><?php 
        esc_html_e('Number', 'total');
        ?>
</label>
			<input class="widefat" name="<?php 
        echo esc_attr($this->get_field_name('number'));
        ?>
" type="number" value="<?php 
        echo esc_attr($number);
        ?>
" />
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('columns'));
        ?>
"><?php 
        esc_html_e('Columns', 'total');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('columns'));
        ?>
">
				<option value="1" <?php 
        selected($columns, '1');
        ?>
>1</option>
				<option value="2" <?php 
        selected($columns, '2');
        ?>
>2</option>
				<option value="3" <?php 
        selected($columns, '3');
        ?>
>3</option>
				<option value="4" <?php 
        selected($columns, '4');
        ?>
>4</option>
				<option value="5" <?php 
        selected($columns, '5');
        ?>
>5</option>
				<option value="6" <?php 
        selected($columns, '6');
        ?>
>6</option>
			</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('img_hover'));
        ?>
"><?php 
        esc_html_e('Image Hover', 'total');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('img_hover'));
        ?>
" style="width:100%;">
				<?php 
        // Get image sizes
        $hovers = wpex_image_hovers();
        // Loop through hovers and add options
        foreach ($hovers as $key => $val) {
            ?>
					<option value="<?php 
            echo esc_attr($key);
            ?>
" <?php 
            selected($img_hover, $key);
            ?>
>
						<?php 
            echo strip_tags($val);
            ?>
					</option>
				<?php 
        }
        ?>
				
			</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('img_size'));
        ?>
"><?php 
        esc_html_e('Image Size', 'total');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo esc_attr($this->get_field_name('img_size'));
        ?>
" style="width:100%;">
			<option value="wpex_custom" <?php 
        selected($img_size, 'wpex_custom');
        ?>
><?php 
        esc_html_e('Custom', 'total');
        ?>
</option>
				<?php 
        // Get image sizes
        $get_img_sizes = wpex_get_thumbnail_sizes();
        ?>

				<?php 
        foreach ($get_img_sizes as $key => $val) {
            ?>
					<option value="<?php 
            echo esc_attr($key);
            ?>
" <?php 
            selected($img_size, $key);
            ?>
><?php 
            echo strip_tags($key);
            ?>
</option>
				<?php 
        }
        ?>
				
			</select>
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('img_width'));
        ?>
"><?php 
        esc_html_e('Image Crop Width', 'total');
        ?>
</label> 
			<input class="widefat" name="<?php 
        echo esc_attr($this->get_field_name('img_width'));
        ?>
" type="text" value="<?php 
        echo esc_attr($img_width);
        ?>
" />
		</p>

		<p>
			<label for="<?php 
        echo esc_attr($this->get_field_id('img_height'));
        ?>
"><?php 
        esc_html_e('Image Crop Height', 'total');
        ?>
</label> 
			<input class="widefat" name="<?php 
        echo esc_attr($this->get_field_name('img_height'));
        ?>
" type="text" value="<?php 
        echo esc_attr($img_height);
        ?>
" />
		</p>
		
	<?php 
    }
    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('title' => __('Recent Posts', 'wpex'), 'number' => '6', 'post_type' => 'post', 'taxonomy' => '', 'terms' => '', 'order' => 'DESC', 'columns' => '3', 'img_size' => 'wpex_custom', 'img_hover' => '', 'img_width' => '', 'img_height' => ''));
        // Sanitize vars
        $title = esc_attr($instance['title']);
        $number = esc_attr($instance['number']);
        $post_type = esc_attr($instance['post_type']);
        $taxonomy = esc_attr($instance['taxonomy']);
        $terms = esc_attr($instance['terms']);
        $order = esc_attr($instance['order']);
        $columns = esc_attr($instance['columns']);
        $img_hover = esc_attr($instance['img_hover']);
        $img_size = esc_attr($instance['img_size']);
        $img_width = esc_attr($instance['img_width']);
        $img_height = esc_attr($instance['img_height']);
        ?>

		<?php 
        /* Title */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'wpex');
        ?>
</label>
			<input class="widefat" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" />
		</p>

		<?php 
        /* Post Type */
        ?>
		<p>
		<label for="<?php 
        echo $this->get_field_id('post_type');
        ?>
"><?php 
        _e('Post Type', 'wpex');
        ?>
</label>
		<br />
		<select class='wpex-select' name="<?php 
        echo $this->get_field_name('post_type');
        ?>
" style="width:100%;">
			<option value="post" <?php 
        if ($post_type == 'post') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Post', 'wpex');
        ?>
</option>
			<?php 
        // Get Post Types
        $args = array('public' => true, '_builtin' => false, 'exclude_from_search' => false);
        $output = 'names';
        $operator = 'and';
        $get_post_types = get_post_types($args, $output, $operator);
        if (!isset($get_post_types['portfolio']) && WPEX_PORTFOLIO_IS_ACTIVE) {
            $obj = get_post_type_object('portfolio');
            $get_post_types['portfolio'] = $obj->labels->name;
        }
        if (!isset($get_post_types['staff']) && WPEX_STAFF_IS_ACTIVE) {
            $obj = get_post_type_object('staff');
            $get_post_types['staff'] = $obj->labels->name;
        }
        if (!isset($get_post_types['testimonials']) && WPEX_TESTIMONIALS_IS_ACTIVE) {
            $obj = get_post_type_object('testimonials');
            $get_post_types['testimonials'] = $obj->labels->name;
        }
        foreach ($get_post_types as $get_post_type) {
            ?>
				<?php 
            if ($get_post_type != 'post') {
                ?>
					<option value="<?php 
                echo $get_post_type;
                ?>
" <?php 
                if ($post_type == $get_post_type) {
                    ?>
selected="selected"<?php 
                }
                ?>
><?php 
                echo ucfirst($get_post_type);
                ?>
</option>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
		</select>
		</p>

		<?php 
        /* Taxonomy */
        ?>
		<p>
		<label for="<?php 
        echo $this->get_field_id('taxonomy');
        ?>
"><?php 
        _e('Query By Taxonomy', 'wpex');
        ?>
</label>
		<br />
		<select class='wpex-select' name="<?php 
        echo $this->get_field_name('taxonomy');
        ?>
" style="width:100%;">
			<option value="post" <?php 
        if (!$taxonomy) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('No', 'wpex');
        ?>
</option>
			<?php 
        // Get Taxonomies
        $get_taxonomies = get_taxonomies(array('public' => true), 'objects');
        ?>
			<?php 
        foreach ($get_taxonomies as $get_taxonomy) {
            ?>
				<option value="<?php 
            echo $get_taxonomy->name;
            ?>
" <?php 
            if ($get_taxonomy->name == $taxonomy) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo ucfirst($get_taxonomy->labels->singular_name);
            ?>
</option>
			<?php 
        }
        ?>
		</select>
		</p>

		<?php 
        /* Terms */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('terms');
        ?>
"><?php 
        _e('Terms', 'wpex');
        ?>
</label>
			<br />
			<input class="widefat" name="<?php 
        echo $this->get_field_name('terms');
        ?>
" type="text" value="<?php 
        echo $terms;
        ?>
" />
			<small><?php 
        _e('Enter the term slugs to query by seperated by a "comma"', 'wpex');
        ?>
</small>
		</p>

		<?php 
        /* Order */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('order');
        ?>
"><?php 
        _e('Order', 'wpex');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo $this->get_field_name('order');
        ?>
" style="width:100%;">
				<option value="DESC" <?php 
        if ($order == 'DESC') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Recent', 'wpex');
        ?>
</option>
				<option value="rand" <?php 
        if ($order == 'rand') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Random', 'wpex');
        ?>
</option>
				<option value="comment_count" <?php 
        if ($order == 'comment_count') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Most Comments', 'wpex');
        ?>
</option>
				<option value="modified" <?php 
        if ($order == 'modified') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Last Modified', 'wpex');
        ?>
</option>
			</select>
		</p>

		<?php 
        /* Number */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('number');
        ?>
"><?php 
        _e('Number', 'wpex');
        ?>
</label>
			<input class="widefat" name="<?php 
        echo $this->get_field_name('number');
        ?>
" type="text" value="<?php 
        echo $number;
        ?>
" />
		</p>

		<?php 
        /* Columns */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('columns');
        ?>
"><?php 
        _e('Columns', 'wpex');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo $this->get_field_name('columns');
        ?>
">
				<option value="1" <?php 
        if ($columns == 1) {
            ?>
selected="selected"<?php 
        }
        ?>
>1</option>
				<option value="2" <?php 
        if ($columns == 2) {
            ?>
selected="selected"<?php 
        }
        ?>
>2</option>
				<option value="3" <?php 
        if ($columns == 3) {
            ?>
selected="selected"<?php 
        }
        ?>
>3</option>
				<option value="4" <?php 
        if ($columns == 4) {
            ?>
selected="selected"<?php 
        }
        ?>
>4</option>
				<option value="5" <?php 
        if ($columns == 5) {
            ?>
selected="selected"<?php 
        }
        ?>
>5</option>
				<option value="6" <?php 
        if ($columns == 6) {
            ?>
selected="selected"<?php 
        }
        ?>
>6</option>
			</select>
		</p>

		<?php 
        /* Image Hover Animation */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('img_hover');
        ?>
"><?php 
        _e('Image Hover', 'wpex');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo $this->get_field_name('img_hover');
        ?>
" style="width:100%;">
				<?php 
        // Get image sizes
        $hovers = wpex_image_hovers();
        // Loop through hovers and add options
        foreach ($hovers as $key => $val) {
            ?>
					<option value="<?php 
            echo $key;
            ?>
" <?php 
            if ($img_hover == $key) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo $val;
            ?>
</option>
				<?php 
        }
        ?>
				
			</select>
		</p>

		<?php 
        /* Image Size */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('img_size');
        ?>
"><?php 
        _e('Image Size', 'wpex');
        ?>
</label>
			<br />
			<select class='wpex-select' name="<?php 
        echo $this->get_field_name('img_size');
        ?>
" style="width:100%;">
			<option value="wpex_custom" <?php 
        if ($img_size == 'wpex_custom') {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e('Custom', 'wpex');
        ?>
</option>
				<?php 
        // Get image sizes
        $get_img_sizes = wpex_get_thumbnail_sizes();
        ?>

				<?php 
        foreach ($get_img_sizes as $key => $val) {
            ?>
					<option value="<?php 
            echo $key;
            ?>
" <?php 
            if ($img_size == $key) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo $key;
            ?>
</option>
				<?php 
        }
        ?>
				
			</select>
		</p>

		<?php 
        /* Image Width */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('img_width');
        ?>
"><?php 
        _e('Image Crop Width', 'wpex');
        ?>
</label> 
			<input class="widefat" name="<?php 
        echo $this->get_field_name('img_width');
        ?>
" type="text" value="<?php 
        echo $img_width;
        ?>
" />
		</p>

		<?php 
        /* Image Height */
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('img_height');
        ?>
"><?php 
        _e('Image Crop Height', 'wpex');
        ?>
</label> 
			<input class="widefat" name="<?php 
        echo $this->get_field_name('img_height');
        ?>
" type="text" value="<?php 
        echo $img_height;
        ?>
" />
		</p>
		
	<?php 
    }
示例#3
0
/**
 * Returns correct HTMl for post thumbnails
 *
 * @since 2.0.0
 */
function wpex_get_post_thumbnail($args = array())
{
    // Check if retina is enabled
    $retina_img = '';
    $attr = array();
    // Default args
    $defaults = array('attachment' => get_post_thumbnail_id(), 'size' => 'full', 'width' => '', 'height' => '', 'crop' => 'center-center', 'alt' => '', 'class' => '', 'return' => 'html', 'style' => '', 'retina' => wpex_global_obj('retina'), 'schema_markup' => false, 'placeholder' => false);
    // Parse args
    $args = wp_parse_args($args, $defaults);
    // Extract args
    extract($args);
    // Return dummy image
    if ('dummy' == $attachment || $placeholder) {
        return '<img src="' . wpex_placeholder_img_src() . '" />';
    }
    // Return if there isn't any attachment
    if (!$attachment) {
        return;
    }
    // Sanitize variables
    $size = 'wpex-custom' == $size ? 'wpex_custom' : $size;
    $size = 'wpex_custom' == $size ? false : $size;
    $crop = !$crop ? 'center-center' : $crop;
    $crop = 'true' == $crop ? 'center-center' : $crop;
    // Image must have an alt
    if (empty($alt)) {
        $alt = get_post_meta($attachment, '_wp_attachment_image_alt', true);
    }
    if (empty($alt)) {
        $alt = trim(strip_tags(get_post_field('post_excerpt', $attachment)));
    }
    if (empty($alt)) {
        $alt = trim(strip_tags(get_the_title($attachment)));
        $alt = str_replace('_', ' ', $alt);
        $alt = str_replace('-', ' ', $alt);
    }
    // Prettify alt attribute
    if ($alt) {
        $alt = ucwords($alt);
    }
    // If image width and height equal '9999' return full image
    if ('9999' == $width && '9999' == $height) {
        $size = $size ? $size : 'full';
        $width = $height = '';
    }
    // Define crop locations
    $crop_locations = array_flip(wpex_image_crop_locations());
    // Set crop location if defined in format 'left-top' and turn into array
    if ($crop && in_array($crop, $crop_locations)) {
        $crop = 'center-center' == $crop ? true : explode('-', $crop);
    }
    // Get attachment URl
    $attachment_url = wp_get_attachment_url($attachment);
    // Return if there isn't any attachment URL
    if (!$attachment_url) {
        return;
    }
    // Add classes
    if ($class) {
        $attr['class'] = $class;
    }
    // Add alt
    if ($alt) {
        $attr['alt'] = esc_attr($alt);
    }
    // Add style
    if ($style) {
        $attr['style'] = $style;
    }
    // Add schema markup
    if ($schema_markup) {
        $attr['itemprop'] = 'image';
    }
    // If on the fly image resizing is enabled or a custom width/height is defined
    if (wpex_get_mod('image_resizing', true) || ($width || $height)) {
        // Add Classes
        if ($class) {
            $class = ' class="' . $class . '"';
        }
        // If size is defined and not equal to wpex_custom
        if ($size && 'wpex_custom' != $size) {
            $dims = wpex_get_thumbnail_sizes($size);
            $width = $dims['width'];
            $height = $dims['height'];
            $crop = !empty($dims['crop']) ? $dims['crop'] : $crop;
        }
        // Crop standard image
        $image = wpex_image_resize(array('image' => $attachment_url, 'width' => $width, 'height' => $height, 'crop' => $crop));
        // Generate retina version
        if ($retina) {
            $retina_img = wpex_generate_retina_image($attachment_url, $width, $height, $crop);
            if ($retina_img) {
                $attr['data-at2x'] = $retina_img;
            } else {
                $attr['data-no-retina'] = '';
            }
        }
        // Return HTMl
        if ($image) {
            // Return image URL
            if ('url' == $return) {
                return $image['url'];
            } else {
                // Add attributes
                $attr = array_map('esc_attr', $attr);
                $html = '';
                foreach ($attr as $name => $value) {
                    $html .= ' ' . esc_attr($name) . '="' . esc_attr($value) . '"';
                }
                // Return img
                return '<img src="' . esc_url($image['url']) . '" width="' . esc_attr($image['width']) . '" height="' . esc_attr($image['height']) . '"' . $html . ' />';
            }
        }
    } else {
        // Sanitize size
        $size = $size ? $size : 'full';
        // Create retina version if retina is enabled (not needed for full images)
        if ($retina) {
            // Retina not needed for full images
            if ('full' != $size) {
                $dims = wpex_get_thumbnail_sizes($size);
                $retina_img = wpex_generate_retina_image($attachment_url, $dims['width'], $dims['height'], $dims['crop']);
            }
            // Add retina tag
            if ($retina_img) {
                $attr['data-at2x'] = $retina_img;
            } else {
                $attr['data-no-retina'] = '';
            }
        }
        // Return image URL
        if ('url' == $return) {
            $src = wp_get_attachment_image_src($attachment, $size, false);
            return $src[0];
        } else {
            return wp_get_attachment_image($attachment, $size, false, $attr);
        }
    }
}