Esempio n. 1
0
function lm_add_feature_image_to_rss($content)
{
    global $post;
    $img_id = false;
    // From post meta, custom field
    $key = apply_filters("rss_image_meta_key", "blog-image");
    if ($key && ($i = get_post_meta(get_the_ID(), $key, true))) {
        $img_id = image_get_attachment_id($i);
    }
    // Fall back to featured image
    if (!$img_id) {
        $img_id = get_post_thumbnail_id();
    }
    // Fall back to first image from post content
    if (!$img_id && ($i = auto_archive_image())) {
        if ($i) {
            $img_id = image_get_attachment_id($i);
        }
    }
    // If we have an image URL, attach it
    if ($img_id) {
        $full_size = smart_media_size((int) $img_id, has_image_size('rssfeed-landscape') ? 'rssfeed-landscape' : 'medium');
        $type = 'image/jpg';
        if (substr($full_size, -3) == 'png') {
            $type = 'image/png';
        }
        echo "\t";
        echo sprintf('<media:content url="%s" medium="image" width="560" height="280" type="%s" />', esc_attr($full_size), esc_attr($type));
        echo "\n";
    }
}
Esempio n. 2
0
/**
 * Adds theme "post-thumbnail" size plus an internationalized version of the image size name to the
 * "add media" modal.  This allows users to insert the image within their post content editor.
 *
 * @author Justin Tadlock <*****@*****.**>
 * @author Cherry Team <*****@*****.**>
 * @since  4.0.0
 * @param  array $sizes Selectable image sizes.
 * @return array
 */
function cherry_image_size_names_choose($sizes)
{
    // If the theme as set a custom post thumbnail size, give it a nice name.
    if (!has_image_size('post-thumbnail')) {
        $sizes['cherry-thumb-s'] = __('Post Thumbnail', 'cherry');
    }
    return $sizes;
}
Esempio n. 3
0
/**
 * Adds theme "post-thumbnail" size plus an internationalized version of the image size name to the 
 * "add media" modal.  This allows users to insert the image within their post content editor.
 *
 * @since  1.3.0
 * @access private
 * @param  array   $sizes  Selectable image sizes.
 * @return array
 */
function hybrid_image_size_names_choose($sizes)
{
    /* If the theme as set a custom post thumbnail size, give it a nice name. */
    if (has_image_size('post-thumbnail')) {
        $sizes['post-thumbnail'] = __('Post Thumbnail', 'hybrid-core');
    }
    /* Return the image size names. */
    return $sizes;
}
	/**
	 * @ticket 26951
	 */
	function test_has_image_size() {
		add_image_size( 'test-size', 200, 600 );
		$this->assertTrue( has_image_size( 'test-size' ) );
	}
/**
 * Creates our "Community" post type and image sizes
 */
function genawpcomm_create_custom_post_type()
{
    $options = get_option('plugin_awp_community_settings');
    if (!isset($options['stylesheet_load'])) {
        $options['stylesheet_load'] = 0;
    }
    if (!isset($options['slug'])) {
        $options['slug'] = 'communities';
    }
    if (!isset($options['singular_name'])) {
        $options['singular_name'] = 'Community';
    }
    if (!isset($options['plural_name'])) {
        $options['plural_name'] = 'Communities';
    }
    if (!isset($options['num_posts'])) {
        $options['num_posts'] = '8';
    }
    if (!isset($options['order_by'])) {
        $options['order_by'] = 'title';
    }
    if (!isset($options['sort_order'])) {
        $options['sort_order'] = 'ASC';
    }
    $args = apply_filters('awp_community_post_type_args', array('labels' => array('name' => $options['plural_name'], 'singular_name' => $options['singular_name'], 'menu_name' => $options['plural_name'], 'name_admin_bar' => $options['singular_name'], 'add_new' => __('Add New', 'genesis-communities-cpt'), 'add_new_item' => __('Add New ', 'genesis-communities-cpt') . $options['singular_name'], 'new_item' => __('New ', 'genesis-communities-cpt') . $options['singular_name'], 'edit_item' => __('Edit ', 'genesis-communities-cpt') . $options['singular_name'], 'view_item' => __('View ', 'genesis-communities-cpt') . $options['singular_name'], 'all_items' => __('All ', 'genesis-communities-cpt') . $options['plural_name'], 'search_items' => __('Search ', 'genesis-communities-cpt') . $options['plural_name'], 'parent_item_colon' => __('Parent ', 'genesis-communities-cpt') . $options['plural_name'] . ':', 'not_found' => __('No ', 'genesis-communities-cpt') . $options['plural_name'] . __(' found.', 'genesis-communities-cpt'), 'not_found_in_trash' => __('No ', 'genesis-communities-cpt') . $options['plural_name'] . __(' found in Trash.', 'genesis-communities-cpt')), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => 'dashicons-admin-home', 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'menu_position' => 21, 'publicly_queryable' => true, 'supports' => array('title', 'editor', 'excerpt', 'comments', 'thumbnail', 'page-attributes', 'genesis-seo', 'genesis-layouts', 'genesis-simple-sidebars', 'genesis-cpt-archives-settings'), 'rewrite' => array('slug' => $options['slug'], 'with_front' => false)));
    register_post_type('awp-community', $args);
    // Add custom image sizes if they don't exist
    if (!has_image_size('awp-feature-community')) {
        add_image_size('awp-feature-community', 440, 300, true);
    }
    if (!has_image_size('awp-feature-small')) {
        add_image_size('awp-feature-small', 340, 140, true);
    }
    if (!has_image_size('awp-feature-wide')) {
        add_image_size('awp-feature-wide', 740, 285, true);
    }
    // Show the custom sizes when choosing image size in media
    add_filter('image_size_names_choose', 'genawpcomm_my_custom_sizes');
    function genawpcomm_my_custom_sizes($sizes)
    {
        return array_merge($sizes, array('awp-feature-community' => __('awp-feature-community', 'genesis-communities-cpt'), 'awp-feature-small' => __('awp-feature-small', 'genesis-communities-cpt'), 'awp-feature-wide' => __('awp-feature-wide', 'genesis-communities-cpt')));
    }
}
        <?php 
the_title('<h3 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h3>');
?>
    </header><!-- .entry-header -->

    <?php 
if (has_post_thumbnail() and !is_search()) {
    ?>
        <a class="post-thumbnail" href="<?php 
    the_permalink();
    ?>
">
        <div class="post-thumbnail">
            <?php 
    // As of WP 3.9, if we don't have the right image size, use medium
    if (function_exists('has_image_size') and !has_image_size('post-thumbnail')) {
        the_post_thumbnail('medium', $attr = array('class' => 'thumbnail img-responsive post-thumbnail'));
        // Otherwise, use our custom size
    } else {
        the_post_thumbnail('post-thumbnail', $attr = array('class' => 'thumbnail img-responsive'));
    }
    //endif has_image_size()
    ?>
        </div>
        </a>
    <?php 
}
?>

     <div class="entry-summary">
        <?php 
Esempio n. 7
0
 /**
  * Adds custom image size.
  *
  * @param string  $size
  * @param number  $width
  * @param number  $height
  * @param boolean $crop
  * @return ThemeImageManager
  */
 public function addCustomImageSize($size, $width = 0, $height = 0, $crop = false)
 {
     if ($size && !has_image_size($size)) {
         $this->sizes[$size] = array('width' => absint($width), 'height' => absint($height), 'crop' => $crop);
     }
     return $this;
 }
 /**
  * Constructor method.  This sets up and runs the show.
  *
  * @since  1.0.0
  * @access public
  * @param  array  $args
  * @return void
  */
 public function __construct($args = array())
 {
     global $wp_embed;
     /* Use WP's embed functionality to handle the [embed] shortcode and autoembeds. */
     add_filter('get_the_image_post_content', array($wp_embed, 'run_shortcode'));
     add_filter('get_the_image_post_content', array($wp_embed, 'autoembed'));
     /* Set the default arguments. */
     $defaults = array('post_id' => get_the_ID(), 'order' => array('meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default'), 'meta_key' => array('Thumbnail', 'thumbnail'), 'featured' => true, 'attachment' => true, 'scan' => false, 'scan_raw' => false, 'callback' => null, 'default' => false, 'split_content' => false, 'size' => has_image_size('post-thumbnail') ? 'post-thumbnail' : 'thumbnail', 'link_to_post' => true, 'image_class' => false, 'width' => false, 'height' => false, 'before' => '', 'after' => '', 'min_width' => 0, 'min_height' => 0, 'caption' => false, 'meta_key_save' => false, 'thumbnail_id_save' => false, 'cache' => true, 'format' => 'img', 'echo' => true, 'custom_key' => null, 'default_size' => null, 'the_post_thumbnail' => null, 'image_scan' => null, 'default_image' => null, 'order_of_image' => null);
     /* Allow plugins/themes to filter the arguments. */
     $this->args = apply_filters('get_the_image_args', wp_parse_args($args, $defaults));
     /* If no post ID, return. */
     if (empty($this->args['post_id'])) {
         return false;
     }
     /* === Handle deprecated arguments. === */
     /* If $default_size is given, overwrite $size. */
     if (!is_null($this->args['default_size'])) {
         $this->args['size'] = $this->args['default_size'];
     }
     /* If $custom_key is set, overwrite $meta_key. */
     if (!is_null($this->args['custom_key'])) {
         $this->args['meta_key'] = $this->args['custom_key'];
     }
     /* If 'the_post_thumbnail' is set, overwrite 'featured'. */
     if (!is_null($this->args['the_post_thumbnail'])) {
         $this->args['featured'] = $this->args['the_post_thumbnail'];
     }
     /* If 'image_scan' is set, overwrite 'scan'. */
     if (!is_null($this->args['image_scan'])) {
         $this->args['scan'] = $this->args['image_scan'];
     }
     /* If 'default_image' is set, overwrite 'default'. */
     if (!is_null($this->args['default_image'])) {
         $this->args['default'] = $this->args['default_image'];
     }
     /* === End deprecated arguments. === */
     /* If $format is set to 'array', don't link to the post. */
     if ('array' == $this->args['format']) {
         $this->args['link_to_post'] = false;
     }
     /* Find images. */
     $this->find();
     /* Only used if $original_image is set. */
     if (true === $this->args['split_content'] && !empty($this->original_image)) {
         add_filter('the_content', array($this, 'split_content'), 9);
     }
 }
Esempio n. 9
0
 /**
  * Convert a WordPress image attachment to a Twitter Card image object
  *
  * @since 1.0.0
  *
  * @param int    $attachment_id WordPress attachment ID
  * @param string $size          desired size
  *
  * @return \Twitter\Cards\Components\Image|null Twitter Card image
  */
 public function attachmentToTwitterImage($attachment_id, $size = 'full')
 {
     if (!(is_string($size) && $size)) {
         $size = 'full';
     }
     // request large version of image if full version exceeds filesize limit
     if ('full' === $size) {
         $attached_file = get_attached_file($attachment_id);
         if ($attached_file && file_exists($attached_file)) {
             $bytes = filesize($attached_file);
             if ($bytes && $bytes > self::MAX_FILESIZE) {
                 /**
                  * Filter the intermediate image size to be provided for Twitter thumbnail when a full-size image exceeds Twitter's filesize limit
                  *
                  * Twitter will consume the largest available image under the filesize limit and generate thumbnails appropriate for Twitter Card display in various dimension and DPI contexts
                  *
                  * @since 1.0.0
                  *
                  * @param string $size          The intermediate size. Default: large
                  * @param int    $attachment_id Attachment identifier
                  */
                 $intermediate_size = apply_filters('twitter_card_intermediate_image_size', 'large', $attachment_id);
                 // check filtered intermediate size to avoid possible infinite loop
                 if (!$intermediate_size || 'full' === $intermediate_size || !has_image_size($intermediate_size)) {
                     return;
                 }
                 return $handler->attachmentToTwitterImage($attachment_id, $intermediate_size);
             }
             unset($bytes);
         }
         unset($attached_file);
     }
     list($url, $width, $height) = wp_get_attachment_image_src($attachment_id, $size);
     if (empty($url)) {
         return;
     }
     $image = new \Twitter\Cards\Components\Image($url);
     if (!empty($width)) {
         $width = absint($width);
         if ($width) {
             if ($width < $this->min_width) {
                 // reject if image width below required width
                 return;
             }
             $image->setWidth($width);
         }
         // width and height are a resizing hint. must exist as a pair
         if (!empty($height)) {
             $height = absint($height);
             if ($height) {
                 if ($height < $this->min_height) {
                     // reject if image height below required height
                     return;
                 }
                 $image->setHeight($height);
             }
         }
     }
     return $image;
 }
Esempio n. 10
0
 /**
  * Method for setting up, parsing, and providing filter hooks for the arguments.
  *
  * @since 1.0.0
  * @access public
  * @return void
  */
 public function set_up_args($attr)
 {
     /* Orderby. */
     if (isset($attr['orderby'])) {
         $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
         if (!$attr['orderby']) {
             unset($attr['orderby']);
         }
     }
     /* Default gallery settings. */
     $defaults = array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => get_the_ID(), 'mime_type' => 'image', 'link' => '', 'itemtag' => 'figure', 'icontag' => 'div', 'captiontag' => 'figcaption', 'columns' => 3, 'size' => has_image_size('post-thumbnail') ? 'post-thumbnail' : 'thumbnail', 'ids' => '', 'include' => '', 'exclude' => '', 'numberposts' => -1, 'offset' => '');
     /* Apply filters to the default arguments. */
     $defaults = apply_filters('hoot_cleaner_gallery_defaults', $defaults);
     /* Merge the defaults with user input.  */
     $this->args = shortcode_atts($defaults, $attr);
     /* Apply filters to the arguments. */
     $this->args = apply_filters('hoot_cleaner_gallery_args', $this->args);
     /* Make sure the post ID is a valid integer. */
     $this->args['id'] = intval($this->args['id']);
     /* Properly escape the gallery tags. */
     $this->args['itemtag'] = tag_escape($this->args['itemtag']);
     $this->args['icontag'] = tag_escape($this->args['icontag']);
     $this->args['captiontag'] = tag_escape($this->args['captiontag']);
 }
Esempio n. 11
0
    function widget($args, $instance)
    {
        if (isset($instance['posts'])) {
            $posts_ids = explode(',', $instance['posts']);
        } else {
            $posts_ids = array();
        }
        if (sizeof($posts_ids) == 0) {
            $posts = get_posts(array('posts_per_page' => 5, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true));
        } else {
            $posts = get_posts(array('post__in' => $posts_ids, 'orderby' => 'date', 'order' => 'DESC'));
        }
        $flag = true;
        ?>
        <div id="myCarousel" class="nwm-carousel carousel slide" data-ride="carousel">
            <div class="carousel-inner" role="listbox">

        <?php 
        foreach ($posts as $post) {
            $categories = wp_get_post_categories($post->ID);
            $image_id = get_post_thumbnail_id($post->ID);
            $image = wp_get_attachment_url($image_id);
            $categories_css = '';
            ?>
        <article class="carousel-post item post type-post status-publish format-standard has-post-thumbnail <?php 
            echo $flag ? 'active' : '';
            ?>
">
            <div class="entry-thumbnail">
                <a href="<?php 
            echo get_permalink($post->ID);
            ?>
">
                    <div class="image nwm-carousel-item-bg-container" style="background-image: url(<?php 
            echo $image;
            ?>
);" data-width="500" data-height="600">
                        <img src="<?php 
            echo $image;
            ?>
">
                    </div>
                </a>
            </div>
            <div class="entry-data nwm-carousel-item-data carousel-caption">
            <div class="entry-header">
                <div class="entry-extra">
                    <span class="categories-links nwm-carousel-item-categories-list">
                        <?php 
            foreach ($categories as $category) {
                $c = get_category($category);
                $categories_css .= 'category-' . $c->slug . ' ';
                ?>
                            <a class="<?php 
                echo $c->slug;
                ?>
" href="" rel="category tag">
                                <?php 
                echo $c->name;
                ?>
                            </a>
                        <?php 
            }
            ?>

                    </span>
                </div>
                <h2 class="entry-title nwm-carousel-item-title">
                    <a href="<?php 
            echo get_permalink($post->ID);
            ?>
" rel="bookmark">
                        <?php 
            echo $post->post_title;
            ?>
                    </a>
                </h2>
            </div>
            <div class="entry-footer">
                <span class="like">
                    <a href="#" class="jm-post-like" data-post_id="<?php 
            echo $post->ID;
            ?>
" title="Like">
                        <i class="icon-unlike"></i>&nbsp;5
                    </a>
                </span>
            </div>

            </div>
          <div class="mi_categoria <?php 
            echo $categories_css;
            ?>
"></div>
        </article>
        <?php 
            $flag = false;
        }
        ?>
    </div>
        <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
        <span aria-hidden="true">&nbsp;</span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
        <span aria-hidden="true">&nbsp;</span>
        <span class="sr-only">Next</span>
      </a>
  </div>

        <?php 
        if (!empty($instance['posts'])) {
            $posts = explode(',', $instance['posts']);
            if (isset($instance['size']) && !has_image_size($instance['size'])) {
                $size_array = explode('x', $instance['size']);
                add_image_size($instance['size'], $size_array[0], $size_array[1], true);
            }
        }
    }
Esempio n. 12
0
function azexo_add_image_size($size)
{
    if (!has_image_size($size) && !in_array($size, array('thumb', 'thumbnail', 'medium', 'large', 'post-thumbnail'))) {
        $size_array = explode('x', $size);
        add_image_size($size, $size_array[0], $size_array[1], true);
    }
}
Esempio n. 13
0
    function widget($args, $instance)
    {
        if (isset($instance['posts'])) {
            $posts_ids = explode(',', $instance['posts']);
        } else {
            $posts_ids = array();
        }
        if (!empty($posts_ids)) {
            $posts = get_posts(array('posts__in' => $posts_ids, 'posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true));
        } else {
            $posts = get_posts(array('posts_per_page' => 5, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true));
        }
        $flag = true;
        ?>
        <div id="myCarousel" class="nwm-carousel carousel slide" data-ride="carousel">
            <div class="carousel-inner" role="listbox">

        <?php 
        foreach ($posts as $post) {
            $categories = wp_get_post_categories($post->ID);
            $image_id = get_post_thumbnail_id($post->ID);
            $image = wp_get_attachment_url($image_id);
            $categories_css = '';
            ?>
        <article class="carousel-post item post type-post status-publish format-standard has-post-thumbnail <?php 
            echo $flag ? 'active' : '';
            ?>
">
            <div class="entry-thumbnail">
                <a href="<?php 
            echo get_permalink($post->ID);
            ?>
">
                    <div class="image nwm-carousel-item-bg-container" style="background-image: url(<?php 
            echo $image;
            ?>
);" data-width="500" data-height="600">
                        <img src="<?php 
            echo $image;
            ?>
">
                    </div>
                </a>
            </div>
            <div class="entry-data nwm-carousel-item-data carousel-caption">
            <div class="entry-header">
                <div class="entry-extra">
                    <span class="categories-links nwm-carousel-item-categories-list">
                        <?php 
            foreach ($categories as $category) {
                $c = get_category($category);
                $categories_css .= 'category-' . $c->slug . ' ';
                ?>
                            <a class="<?php 
                echo $c->slug;
                ?>
" href="" rel="category tag">
                                <?php 
                echo $c->name;
                ?>
                            </a>
                        <?php 
            }
            ?>

                    </span>
                </div>
                <h2 class="entry-title nwm-carousel-item-title">
                    <a href="<?php 
            echo get_permalink($post->ID);
            ?>
" rel="bookmark">
                        <?php 
            echo $post->post_title;
            ?>
                    </a>
                </h2>
            </div>
            <div class="entry-footer">
                <span class="like">
                    <a href="#" class="jm-post-like" data-post_id="<?php 
            echo $post->ID;
            ?>
" title="Like">
                        <i class="icon-unlike"></i>&nbsp;5
                    </a>
                </span>
            </div>

            </div>
          <div class="mi_categoria <?php 
            echo $categories_css;
            ?>
"></div>
        </article>
        <?php 
            $flag = false;
        }
        ?>
    </div>
        <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
        <span aria-hidden="true">&nbsp;</span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
        <span aria-hidden="true">&nbsp;</span>
        <span class="sr-only">Next</span>
      </a>
  </div>

        <?php 
        if (!empty($instance['posts'])) {
            $posts = explode(',', $instance['posts']);
            if (isset($instance['size']) && !has_image_size($instance['size'])) {
                $size_array = explode('x', $instance['size']);
                add_image_size($instance['size'], $size_array[0], $size_array[1], true);
            }
            /*
            print '<div class="" data-width="' . $_wp_additional_image_sizes[$instance['size']]['width'] . '" data-height="' . $_wp_additional_image_sizes[$instance['size']]['height'] . '">';
            foreach ($posts as $p) {
                $post = get_post($p);
                print '<div class="item">';
                $image_src = azexo_get_attachment_image_src(get_post_thumbnail_id($p), $instance['size']);
                print '<div class="image" style="background-image: url(\'' . $image_src[0] . '\')"></div>';
                print '<div class="details">';
                print '<div class="title"><a href="' . esc_url(get_permalink($p)) . '" rel="bookmark">' . get_the_title($p) . '</a></div>';
                print '<div class="categories">' . get_the_category_list(__(', ', AZEXO_THEME_NAME), '', $p) . '</div>';
                print '<div class="date">' . azexo_entry_date(false, $post) . '</div>';
                if ($instance['excerpt'] == 'on') {
                    setup_postdata($post);
                    print '<div class="excerpt">' . wp_trim_words(apply_filters('get_the_excerpt', $post->post_excerpt), 20) . '</div>';
                }
                print '</div>';
                print '</div>';
            }
            print '</div>';
            */
        }
    }