コード例 #1
0
ファイル: post.php プロジェクト: ThemeButler/tm-demo
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail()) {
        return false;
    }
    global $post;
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              large size.
     */
    $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
    if (empty($edit_args)) {
        $image = beans_get_post_attachment($post->ID, 'large');
    } else {
        $image = beans_edit_post_attachment($post->ID, $edit_args);
    }
    echo beans_open_markup('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        echo beans_open_markup('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    echo beans_selfclose_markup('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => esc_attr($image->alt)), $image);
    if (!is_singular()) {
        echo beans_close_markup('beans_post_image_link', 'a');
    }
    echo beans_close_markup('beans_post_image', 'div');
}
コード例 #2
0
ファイル: post.php プロジェクト: Getbeans/Beans
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail() || !current_theme_supports('post-thumbnails')) {
        return false;
    }
    global $post;
    /**
     * Filter whether Beans should handle the image edition (resize) or let WP do so.
     *
     * @since 1.2.5
     *
     * @param bool $edit True to use Beans Image API to handle the image edition (resize), false to let {@link http://codex.wordpress.org/Function_Reference/the_post_thumbnail the_post_thumbnail()} taking care of it. Default true.
     */
    $edit = apply_filters('beans_post_image_edit', true);
    if ($edit) {
        /**
         * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
         *
         * @since 1.0.0
         *
         * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
         *                              large size.
         */
        $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
        if (empty($edit_args)) {
            $image = beans_get_post_attachment($post->ID, 'large');
        } else {
            $image = beans_edit_post_attachment($post->ID, $edit_args);
        }
        /**
         * Filter the arguments used by {@see beans_edit_image()} to edit the post small image.
         *
         * The small image is only used for screens equal or smaller than the image width set, which is 480px by default.
         *
         * @since 1.0.0
         *
         * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
         *                              small size.
         */
        $edit_small_args = apply_filters('beans_edit_post_image_small_args', array('resize' => array(480, false)));
        if (empty($edit_small_args)) {
            $image_small = beans_get_post_attachment($post->ID, 'thumbnail');
        } else {
            $image_small = beans_edit_post_attachment($post->ID, $edit_small_args);
        }
    }
    beans_open_markup_e('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        beans_open_markup_e('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    beans_open_markup_e('beans_post_image_item_wrap', 'picture');
    if ($edit) {
        beans_selfclose_markup_e('beans_post_image_small_item', 'source', array('media' => '(max-width: ' . $image_small->width . 'px)', 'srcset' => esc_url($image_small->src)), $image_small);
        beans_selfclose_markup_e('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => $image->alt, 'itemprop' => 'image'), $image);
    } else {
        // Beans API isn't available, use wp_get_attachment_image_attributes filter instead.
        the_post_thumbnail();
    }
    beans_close_markup_e('beans_post_image_item_wrap', 'picture');
    if (!is_singular()) {
        beans_close_markup_e('beans_post_image_link', 'a');
    }
    beans_close_markup_e('beans_post_image', 'div');
}
コード例 #3
0
ファイル: post.php プロジェクト: JoomPassion/Beans
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail()) {
        return false;
    }
    global $post;
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              large size.
     */
    $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
    if (empty($edit_args)) {
        $image = beans_get_post_attachment($post->ID, 'large');
    } else {
        $image = beans_edit_post_attachment($post->ID, $edit_args);
    }
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post small image.
     *
     * The small image is only used for screens equal or smaller than the image width set, which is 480px by default.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              small size.
     */
    $edit_small_args = apply_filters('beans_edit_post_image_small_args', array('resize' => array(480, false)));
    if (empty($edit_small_args)) {
        $image_small = beans_get_post_attachment($post->ID, 'small');
    } else {
        $image_small = beans_edit_post_attachment($post->ID, $edit_small_args);
    }
    echo beans_open_markup('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        echo beans_open_markup('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    echo beans_open_markup('beans_post_image_item_wrap', 'picture');
    echo beans_selfclose_markup('beans_post_image_small_item', 'source', array('media' => '(max-width: ' . $image_small->width . 'px)', 'srcset' => $image_small->src), $image_small);
    echo beans_selfclose_markup('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => esc_attr($image->alt), 'itemprop' => 'image'), $image);
    echo beans_close_markup('beans_post_image_item_wrap', 'picture');
    if (!is_singular()) {
        echo beans_close_markup('beans_post_image_link', 'a');
    }
    echo beans_close_markup('beans_post_image', 'div');
}