• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_post_galleries函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_post_galleries函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_galleries函数的具体用法?PHP get_post_galleries怎么用?PHP get_post_galleries使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_post_galleries函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: from_gallery

 /**
  * If a gallery is detected, then get all the images from it.
  */
 static function from_gallery($post_id)
 {
     $images = array();
     $post = get_post($post_id);
     if (!empty($post->post_password)) {
         return $images;
     }
     $permalink = get_permalink($post->ID);
     $galleries = get_post_galleries($post->ID, false);
     foreach ($galleries as $gallery) {
         if (isset($gallery['type']) && 'slideshow' === $gallery['type'] && !empty($gallery['ids'])) {
             $image_ids = explode(',', $gallery['ids']);
             $image_size = isset($gallery['size']) ? $gallery['size'] : 'thumbnail';
             foreach ($image_ids as $image_id) {
                 $image = wp_get_attachment_image_src($image_id, $image_size);
                 if (!empty($image[0])) {
                     list($raw_src) = explode('?', $image[0]);
                     // pull off any Query string (?w=250)
                     $raw_src = wp_specialchars_decode($raw_src);
                     // rawify it
                     $raw_src = esc_url_raw($raw_src);
                     // clean it
                     $images[] = array('type' => 'image', 'from' => 'gallery', 'src' => $raw_src, 'href' => $permalink);
                 }
             }
         } elseif (!empty($gallery['src'])) {
             foreach ($gallery['src'] as $src) {
                 list($raw_src) = explode('?', $src);
                 // pull off any Query string (?w=250)
                 $raw_src = wp_specialchars_decode($raw_src);
                 // rawify it
                 $raw_src = esc_url_raw($raw_src);
                 // clean it
                 $images[] = array('type' => 'image', 'from' => 'gallery', 'src' => $raw_src, 'href' => $permalink);
             }
         }
     }
     return $images;
 }
开发者ID:elliott-stocks,项目名称:jetpack,代码行数:42,代码来源:class.jetpack-post-images.php


示例2: get_post_galleries_images

/**
 * Retrieve the image srcs from galleries from a post's content, if present
 *
 * @since 3.6.0
 *
 * @see get_post_galleries()
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return array A list of lists, each containing image srcs parsed.
 *               from an expanded shortcode
 */
function get_post_galleries_images($post = 0)
{
    $galleries = get_post_galleries($post, false);
    return wp_list_pluck($galleries, 'src');
}
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:16,代码来源:media.php


示例3: et_gallery_images

    function et_gallery_images()
    {
        $output = $images_ids = '';
        if (function_exists('get_post_galleries')) {
            $galleries = get_post_galleries(get_the_ID(), false);
            if (empty($galleries)) {
                return false;
            }
            foreach ($galleries as $gallery) {
                // Grabs all attachments ids from one or multiple galleries in the post
                $images_ids .= ('' !== $images_ids ? ',' : '') . $gallery['ids'];
            }
            $attachments_ids = explode(',', $images_ids);
            // Removes duplicate attachments ids
            $attachments_ids = array_unique($attachments_ids);
        } else {
            $pattern = get_shortcode_regex();
            preg_match("/{$pattern}/s", get_the_content(), $match);
            $atts = shortcode_parse_atts($match[3]);
            if (isset($atts['ids'])) {
                $attachments_ids = explode(',', $atts['ids']);
            } else {
                return false;
            }
        }
        $slides = '';
        foreach ($attachments_ids as $attachment_id) {
            $attachment_attributes = wp_get_attachment_image_src($attachment_id, 'et-pb-post-main-image-fullwidth');
            $attachment_image = !is_single() ? $attachment_attributes[0] : wp_get_attachment_image($attachment_id, 'et-pb-portfolio-image');
            if (!is_single()) {
                $slides .= sprintf('<div class="et_pb_slide" style="background: url(%1$s);"></div>', esc_attr($attachment_image));
            } else {
                $full_image = wp_get_attachment_image_src($attachment_id, 'full');
                $full_image_url = $full_image[0];
                $attachment = get_post($attachment_id);
                $slides .= sprintf('<li class="et_gallery_item">
					<a href="%1$s" title="%3$s">
						<span class="et_portfolio_image">
							%2$s
							<span class="et_overlay"></span>
						</span>
					</a>
				</li>', esc_url($full_image_url), $attachment_image, esc_attr($attachment->post_title));
            }
        }
        if (!is_single()) {
            $output = '<div class="et_pb_slider et_pb_slider_fullwidth_off">
				<div class="et_pb_slides">
					%1$s
				</div>
			</div>';
        } else {
            $output = '<ul class="et_post_gallery clearfix">
				%1$s
			</ul>';
        }
        printf($output, $slides);
    }
开发者ID:ahmedghazi,项目名称:tpls,代码行数:58,代码来源:functions.php


示例4: et_gallery_images

 function et_gallery_images()
 {
     $output = $images_ids = '';
     if (function_exists('get_post_galleries')) {
         $galleries = get_post_galleries(get_the_ID(), false);
         if (empty($galleries)) {
             return false;
         }
         foreach ($galleries as $gallery) {
             // Grabs all attachments ids from one or multiple galleries in the post
             $images_ids .= ('' !== $images_ids ? ',' : '') . $gallery['ids'];
         }
         $attachments_ids = explode(',', $images_ids);
         // Removes duplicate attachments ids
         $attachments_ids = array_unique($attachments_ids);
     } else {
         $pattern = get_shortcode_regex();
         preg_match("/{$pattern}/s", get_the_content(), $match);
         if (empty($match)) {
             return false;
         }
         $atts = shortcode_parse_atts($match[3]);
         if (isset($atts['ids'])) {
             $attachments_ids = explode(',', $atts['ids']);
         } else {
             return false;
         }
     }
     echo '<ul id="et-projects" class="clearfix">';
     foreach ($attachments_ids as $attachment_id) {
         $attachment = get_post($attachment_id);
         $fullimage_attributes = wp_get_attachment_image_src($attachment_id, 'full');
         printf('<li><a href="%s" class="fancybox" rel="gallery" title="%s">%s<span class="project-description"><span class="et-zoom"></span></span></a></li>', esc_url($fullimage_attributes[0]), esc_attr($attachment->post_title), wp_get_attachment_image($attachment_id, 'et-project-thumb'));
     }
     echo '</ul>';
     return $output;
 }
开发者ID:iinspiration,项目名称:theme,代码行数:37,代码来源:functions.php


示例5: hybrid_get_gallery_item_count

/**
 * Gets the gallery *item* count.  This is different from getting the gallery *image* count.  By default, 
 * WordPress only allows attachments with the 'image' mime type in galleries.  However, some scripts such 
 * as Cleaner Gallery allow for other mime types.  This is a more accurate count than the 
 * hybrid_get_gallery_image_count() function since it will count all gallery items regardless of mime type.
 *
 * @todo Check for the [gallery] shortcode with the 'mime_type' parameter and use that in get_posts().
 *
 * @since  1.6.0
 * @access public
 * @return int
 */
function hybrid_get_gallery_item_count()
{
    /* Check the post content for galleries. */
    $galleries = get_post_galleries(get_the_ID(), true);
    /* If galleries were found in the content, get the gallery item count. */
    if (!empty($galleries)) {
        $items = '';
        foreach ($galleries as $gallery => $gallery_items) {
            $items .= $gallery_items;
        }
        preg_match_all('#src=([\'"])(.+?)\\1#is', $items, $sources, PREG_SET_ORDER);
        if (!empty($sources)) {
            return count($sources);
        }
    }
    /* If an item count wasn't returned, get the post attachments. */
    $attachments = get_posts(array('fields' => 'ids', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1));
    /* Return the attachment count if items were found. */
    if (!empty($attachments)) {
        return count($attachments);
    }
    /* Return 0 for everything else. */
    return 0;
}
开发者ID:RA2WP,项目名称:RA2WP,代码行数:36,代码来源:post-formats.php


示例6: widget

    /**
     * Output the HTML for this widget.
     *
     * @access public
     * @since Twenty Fourteen 1.0
     *
     * @param array $args     An array of standard parameters for widgets in this theme.
     * @param array $instance An array of settings for this widget instance.
     */
    public function widget($args, $instance)
    {
        $format = isset($instance['format']) && in_array($instance['format'], $this->formats) ? $instance['format'] : 'aside';
        switch ($format) {
            case 'image':
                $format_string = __('Images', 'twentyfourteen');
                $format_string_more = __('More images', 'twentyfourteen');
                break;
            case 'video':
                $format_string = __('Videos', 'twentyfourteen');
                $format_string_more = __('More videos', 'twentyfourteen');
                break;
            case 'audio':
                $format_string = __('Audio', 'twentyfourteen');
                $format_string_more = __('More audio', 'twentyfourteen');
                break;
            case 'quote':
                $format_string = __('Quotes', 'twentyfourteen');
                $format_string_more = __('More quotes', 'twentyfourteen');
                break;
            case 'link':
                $format_string = __('Links', 'twentyfourteen');
                $format_string_more = __('More links', 'twentyfourteen');
                break;
            case 'gallery':
                $format_string = __('Galleries', 'twentyfourteen');
                $format_string_more = __('More galleries', 'twentyfourteen');
                break;
            case 'aside':
            default:
                $format_string = __('Asides', 'twentyfourteen');
                $format_string_more = __('More asides', 'twentyfourteen');
                break;
        }
        $number = empty($instance['number']) ? 2 : absint($instance['number']);
        $title = apply_filters('widget_title', empty($instance['title']) ? $format_string : $instance['title'], $instance, $this->id_base);
        $ephemera = new WP_Query(array('order' => 'DESC', 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'post__not_in' => get_option('sticky_posts'), 'tax_query' => array(array('taxonomy' => 'post_format', 'terms' => array("post-format-{$format}"), 'field' => 'slug', 'operator' => 'IN'))));
        if ($ephemera->have_posts()) {
            $tmp_content_width = $GLOBALS['content_width'];
            $GLOBALS['content_width'] = 306;
            echo $args['before_widget'];
            ?>
			<h1 class="widget-title <?php 
            echo esc_attr($format);
            ?>
">
				<a class="entry-format" href="<?php 
            echo esc_url(get_post_format_link($format));
            ?>
"><?php 
            echo $title;
            ?>
</a>
			</h1>
			<ol>

				<?php 
            while ($ephemera->have_posts()) {
                $ephemera->the_post();
                $tmp_more = $GLOBALS['more'];
                $GLOBALS['more'] = 0;
                ?>
				<li>
				<article <?php 
                post_class();
                ?>
>
					<div class="entry-content">
						<?php 
                if (has_post_format('gallery')) {
                    if (post_password_required()) {
                        the_content(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen'));
                    } else {
                        $images = array();
                        $galleries = get_post_galleries(get_the_ID(), false);
                        if (isset($galleries[0]['ids'])) {
                            $images = explode(',', $galleries[0]['ids']);
                        }
                        if (!$images) {
                            $images = get_posts(array('fields' => 'ids', 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment'));
                        }
                        $total_images = count($images);
                        if (has_post_thumbnail()) {
                            $post_thumbnail = get_the_post_thumbnail();
                        } elseif ($total_images > 0) {
                            $image = array_shift($images);
                            $post_thumbnail = wp_get_attachment_image($image, 'post-thumbnail');
                        }
                        if (!empty($post_thumbnail)) {
                            ?>
						<a href="<?php 
//.........这里部分代码省略.........
开发者ID:tatakauashi,项目名称:meiteampower,代码行数:101,代码来源:widgets.php


示例7: the_ID

the_ID();
?>
" <?php 
post_class();
?>
>
	<?php 
twentyfourteen_post_thumbnail();
?>

	<?php 
get_template_part('partials/entry-header');
?>

	<div class="entry-content">
		<?php 
$galleries = get_post_galleries(get_the_ID());
if (isset($galleries[0])) {
    echo $galleries[0];
} else {
    the_content(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen'));
}
wp_link_pages(array('before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'twentyfourteen') . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>'));
?>
	</div><!-- .entry-content -->

	<?php 
the_tags('<footer class="entry-meta"><span class="tag-links">', '', '</span></footer>');
?>
</article><!-- #post-## -->
开发者ID:tomharrigan,项目名称:twenty-fourteen-post-styles-child,代码行数:30,代码来源:content-gallery.php


示例8: fastfood_gallery_merge

/**
 * Print a gallery by merging all the galleries in the post.
 * If no [gallery] found, it creates a gallery using the images attached to post
 * 
 * Based on \wp-includes\media.php -> gallery_shortcode().
 * 
 * @since 0.37
 *
 * @param array $attr {
 *     @type int    $id         Post ID.
 *     @type string $class      Gallery class.
 *     @type int    $columns    Number of columns.
 *     @type int    $slice      Max number of items.
 * }
 * @return	int	The number of items in merged gallery
 */
function fastfood_gallery_merge($args)
{
    global $post;
    $defaults = array('id' => $post->ID, 'class' => '', 'columns' => 3, 'slice' => 0);
    $args = wp_parse_args($args, $defaults);
    $galleries = get_post_galleries($args['id'], false);
    $result = array();
    foreach ($galleries as $gallery) {
        $result = array_merge($result, wp_list_pluck(fastfood_get_gallery_items($gallery), 'ID'));
    }
    if (!$result) {
        $result = wp_list_pluck(get_children(array('post_parent' => $args['id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')), 'ID');
    }
    if (!($count = count($result))) {
        return 0;
    }
    if ($args['slice']) {
        $result = array_slice($result, 0, absint($args['slice']));
        $args['columns'] = count($result) - 1;
    }
    $args['class'] = esc_attr(join(' ', array('gallery', 'gallery-columns-' . $args['columns'], $args['class'])));
    $output = "<div class='{$args['class']}'>";
    foreach ($result as $key => $id) {
        $size = $key ? 'thumbnail' : 'full';
        $image_output = wp_get_attachment_image($id, $size, false);
        $image_output = $key ? $image_output : '<a href="' . get_permalink($args['id']) . '">' . $image_output . '</a>';
        $image_meta = wp_get_attachment_metadata($id);
        $orientation = '';
        if (isset($image_meta['height'], $image_meta['width'])) {
            $orientation = $image_meta['height'] > $image_meta['width'] ? 'portrait' : 'landscape';
        }
        $output .= "<dl class='gallery-item'>";
        $output .= "\n\t\t\t<dt class='gallery-icon {$orientation}'>\n\t\t\t\t{$image_output}\n\t\t\t</dt>";
        $output .= "</dl>";
    }
    $output .= "</div>";
    echo $output;
    return $count;
}
开发者ID:TwoBeers,项目名称:fastfood,代码行数:55,代码来源:formats-functions.php


示例9: serene_gallery_images

 function serene_gallery_images()
 {
     $output = $images_ids = '';
     if (function_exists('get_post_galleries')) {
         $galleries = get_post_galleries(get_the_ID(), false);
         if (empty($galleries)) {
             return false;
         }
         if (isset($galleries[0]['ids'])) {
             foreach ($galleries as $gallery) {
                 // Grabs all attachments ids from one or multiple galleries in the post
                 $images_ids .= ('' !== $images_ids ? ',' : '') . $gallery['ids'];
             }
             $attachments_ids = explode(',', $images_ids);
             // Removes duplicate attachments ids
             $attachments_ids = array_unique($attachments_ids);
         } else {
             $attachments_ids = get_posts(array('fields' => 'ids', 'numberposts' => 999, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment'));
         }
     } else {
         $pattern = get_shortcode_regex();
         preg_match("/{$pattern}/s", get_the_content(), $match);
         $atts = shortcode_parse_atts($match[3]);
         if (isset($atts['ids'])) {
             $attachments_ids = explode(',', $atts['ids']);
         } else {
             return false;
         }
     }
     echo '<div class="et-gallery-slider flexslider">';
     echo '	<ul class="et-gallery-slides">';
     foreach ($attachments_ids as $attachment_id) {
         printf('<li class="et-gallery-slide"><a href="%s">%s</a></li>', esc_url(get_permalink()), wp_get_attachment_image($attachment_id, 'serene-featured-image'));
     }
     echo '	</ul> <!-- .et-gallery-slides -->';
     echo '</div> <!-- .et-gallery-slider -->';
     return $output;
 }
开发者ID:sylverman,项目名称:fundacionomnilife,代码行数:38,代码来源:functions.php


示例10: et_gallery_images

    function et_gallery_images()
    {
        $output = $images_ids = '';
        if (function_exists('get_post_galleries')) {
            $galleries = get_post_galleries(get_the_ID(), false);
            if (empty($galleries)) {
                return false;
            }
            foreach ($galleries as $gallery) {
                if (isset($gallery['ids'])) {
                    // Grabs all attachments ids from one or multiple galleries in the post
                    $images_ids .= ('' !== $images_ids ? ',' : '') . $gallery['ids'];
                } else {
                    $image_ids = false;
                    // If user doesn't define ids of images on galleries, get attached media
                    $attached_media = get_attached_media('image', get_the_id());
                }
            }
            if ($images_ids) {
                $attachments_ids = explode(',', $images_ids);
            } elseif (isset($attached_media) && is_array($attached_media) && !empty($attached_media)) {
                $attachments_ids = wp_list_pluck($attached_media, 'ID');
            } else {
                $attachments_ids = false;
            }
            if (!$attachments_ids) {
                // Print no gallery found message
                ?>
			<div class="et_pb_module et_pb_slider et_pb_slider_fullwidth_off et_pb_bg_layout_light gallery-not-found">
				<div class="et_pb_slides">
					<div class="et_pb_slide et_pb_bg_layout_light et_pb_media_alignment_center et-pb-active-slide" style="background-color:#ffffff;">
						<div class="et_pb_container clearfix">
							<div class="et_pb_slide_description">
								<h2><?php 
                _e('No Gallery Found', 'Divi');
                ?>
</h2>
								<div class="et_pb_slide_content">
									<p><?php 
                _e('No items found', 'Divi');
                ?>
</p>
								</div>
							</div> <!-- .et_pb_slide_description -->
						</div> <!-- .et_pb_container -->
					</div> <!-- .et_pb_slide -->
				</div> <!-- .et_pb_slides -->
			</div>
			<?php 
                return;
            }
            // Removes duplicate attachments ids
            $attachments_ids = array_unique($attachments_ids);
        } else {
            $pattern = get_shortcode_regex();
            preg_match("/{$pattern}/s", get_the_content(), $match);
            $atts = shortcode_parse_atts($match[3]);
            if (isset($atts['ids'])) {
                $attachments_ids = explode(',', $atts['ids']);
            } else {
                return false;
            }
        }
        $slides = '';
        foreach ($attachments_ids as $attachment_id) {
            $attachment_attributes = wp_get_attachment_image_src($attachment_id, 'et-pb-post-main-image-fullwidth');
            $attachment_image = !is_single() ? $attachment_attributes[0] : wp_get_attachment_image($attachment_id, 'et-pb-portfolio-image');
            if (!is_single()) {
                $slides .= sprintf('<div class="et_pb_slide" style="background: url(%1$s);"></div>', esc_attr($attachment_image));
            } else {
                $full_image = wp_get_attachment_image_src($attachment_id, 'full');
                $full_image_url = $full_image[0];
                $attachment = get_post($attachment_id);
                $slides .= sprintf('<li class="et_gallery_item">
					<a href="%1$s" title="%3$s">
						<span class="et_portfolio_image">
							%2$s
							<span class="et_overlay"></span>
						</span>
					</a>
				</li>', esc_url($full_image_url), $attachment_image, esc_attr($attachment->post_title));
            }
        }
        if (!is_single()) {
            $output = '<div class="et_pb_slider et_pb_slider_fullwidth_off et_pb_gallery_post_type">
				<div class="et_pb_slides">
					%1$s
				</div>
			</div>';
        } else {
            $output = '<ul class="et_post_gallery clearfix">
				%1$s
			</ul>';
        }
        printf($output, $slides);
    }
开发者ID:Lumbe,项目名称:dev_servus,代码行数:96,代码来源:functions.php


示例11: addPostImages

 /**
  * Add images associated with a WP_Post up to limit.
  *
  * @since 1.0.0
  *
  * @param WP_Post $post post of interest
  *
  * @return void
  */
 public function addPostImages($post)
 {
     // bad parameter
     if (!$post || !isset($post->ID)) {
         return;
     }
     // does current post type and the current theme support post thumbnails?
     if (post_type_supports(get_post_type($post), 'thumbnail') && function_exists('has_post_thumbnail') && has_post_thumbnail()) {
         if ($this->addImageByAttachmentID(get_post_thumbnail_id($post->ID))) {
             if ($this->isFull()) {
                 return;
             }
         }
     }
     // image attachments
     $attached_images = get_attached_media('image', $post);
     if (!empty($attached_images)) {
         foreach ($attached_images as $attached_image) {
             if (!isset($attached_image->ID)) {
                 continue;
             }
             if (!$this->addImageByAttachmentID($attached_image->ID)) {
                 continue;
             }
             // hit the limit. end the search
             if ($this->isFull()) {
                 return;
             }
         }
     }
     unset($attached_images);
     // post galleries
     $galleries = get_post_galleries($post, false);
     foreach ($galleries as $gallery) {
         if (!(isset($gallery['ids']) && $gallery['ids'])) {
             continue;
         }
         $gallery_ids = explode(',', $gallery['ids']);
         foreach ($gallery_ids as $attachment_id) {
             if (!$this->addImageByAttachmentID($attachment_id)) {
                 continue;
             }
             // hit the limit. end the search
             if ($this->isFull()) {
                 return;
             }
         }
         unset($gallery_ids);
     }
     unset($galleries);
 }
开发者ID:cemoulto,项目名称:wordpress,代码行数:60,代码来源:ImageHandler.php


示例12: hannover_get_gallery_images

/**
 * Fetch image post objects for all gallery images in a post.
 *
 * @param $post_id
 *
 * @return array
 */
function hannover_get_gallery_images($post_id)
{
    $post = get_post($post_id);
    // Den Beitrag gibt es nicht, oder er ist leer.
    if (!$post || empty($post->post_content)) {
        return array();
    }
    $galleries = get_post_galleries($post, false);
    if (empty($galleries)) {
        return array();
    }
    $ids = array();
    foreach ($galleries as $gallery) {
        if (!empty($gallery['ids'])) {
            $ids = array_merge($ids, explode(',', $gallery['ids']));
        }
    }
    $ids = array_unique($ids);
    if (empty($ids)) {
        $attachments = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
        if (empty($attachments)) {
            return array();
        }
    }
    $images = get_posts(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'post__in', 'numberposts' => 999, 'include' => $ids));
    if (!$images && !$attachments) {
        return array();
    } elseif (!$images) {
        $images = $attachments;
    }
    return $images;
}
开发者ID:vaskaloidis,项目名称:kaloidistech,代码行数:39,代码来源:functions.php


示例13: get_og_images

 /**
  * Identify image attachments related to the post.
  *
  * Request the full size of the attachment, not necessarily the same as the size used in the post.
  *
  * @since 1.5
  *
  * @param stdClass|WP_Post $post WordPress post of interest
  * @return array {
  *     Open Graph protocol image structured data
  *
  *     @type string URL of the image
  *     @type array associative array of image data
  * }
  */
 public static function get_og_images($post)
 {
     $og_images = array();
     if (!$post || !isset($post->ID)) {
         return $og_images;
     }
     // does current post type and the current theme support post thumbnails?
     if (post_type_supports(get_post_type($post), 'thumbnail') && function_exists('has_post_thumbnail') && has_post_thumbnail()) {
         list($post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height) = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
         $image = self::attachment_to_og_image(get_post_thumbnail_id($post->ID));
         if (isset($image['url']) && !isset($og_images[$image['url']])) {
             $og_images[$image['url']] = $image;
         }
         unset($image);
     }
     // get image attachments
     if (function_exists('get_attached_media')) {
         $images = get_attached_media('image', $post->ID);
         if (!empty($images)) {
             foreach ($images as $i) {
                 if (!isset($i->ID)) {
                     continue;
                 }
                 $image = self::attachment_to_og_image($i->ID);
                 if (!isset($image['url']) || isset($og_images[$image['url']])) {
                     continue;
                 }
                 $og_images[$image['url']] = $image;
                 if (count($og_images) === self::MAX_IMAGE_COUNT) {
                     return $og_images;
                 }
             }
         }
         unset($images);
     }
     // test for WP_Embed handled images
     if (!empty($post->post_content)) {
         // Instagram
         preg_match_all('#\\s*http://instagr(\\.am|am\\.com)/p/(.*)/\\s*#i', $post->post_content, $matches);
         if (isset($matches[2])) {
             foreach ($matches[2] as $instagram_id) {
                 $instagram_url = esc_url_raw('http://instagram.com/p/' . $instagram_id . '/media/?size=l', array('http'));
                 if (!$instagram_url || isset($og_images[$instagram_url])) {
                     continue;
                 }
                 $og_images[$instagram_url] = array('url' => $instagram_url);
                 unset($instagram_url);
             }
         }
         unset($matches);
     }
     // add gallery content
     if (function_exists('get_post_galleries')) {
         // use get_post_galleries function from WP 3.6+
         $galleries = get_post_galleries($post, false);
         foreach ($galleries as $gallery) {
             // use ids to request full-size image URI
             if (!(isset($gallery['ids']) && $gallery['ids'])) {
                 continue;
             }
             $gallery['ids'] = explode(',', $gallery['ids']);
             foreach ($gallery['ids'] as $attachment_id) {
                 $image = self::attachment_to_og_image($attachment_id);
                 if (!isset($image['url']) || isset($og_images[$image['url']])) {
                     continue;
                 }
                 $og_images[$image['url']] = $image;
                 if (count($og_images) === self::MAX_IMAGE_COUNT) {
                     return $og_images;
                 }
                 unset($image);
             }
         }
         unset($galleries);
     } else {
         // extract full-size images from gallery shortcode
         $og_images = self::gallery_images($post, $og_images);
     }
     return $og_images;
 }
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:95,代码来源:open-graph-protocol.php


示例14: update_gallery

 function update_gallery($action, $pid)
 {
     global $wpdb;
     $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
     $posts = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . 'posts');
     foreach ($posts as $post) {
         if (in_array($post->post_type, $post_types)) {
             $galleries = get_post_galleries($post->ID, false);
             foreach ($galleries as $gallery) {
                 $ids_old = 'ids="' . $gallery['ids'] . '"';
                 $ids_old_array = explode(',', $gallery['ids']);
                 if (isset($gallery['autoinsert']) && $gallery['autoinsert'] == 1) {
                     if ($action == 'upload' || $action == 'update') {
                         $ids_new_array = $this->upload_update_post($gallery, $ids_old_array);
                         $ids_new = 'ids="' . trim(implode(',', $ids_new_array), ',') . '"';
                         if ($ids_new_array != $ids_old_array) {
                             $post_content = str_replace($ids_old, $ids_new, $post->post_content);
                             wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content));
                         }
                     } else {
                         if ($action == 'delete') {
                             if (in_array($pid, $ids_old_array) == true) {
                                 $key = array_search($pid, $ids_old_array);
                                 unset($ids_old_array[$key]);
                             }
                             $ids_new = 'ids="' . trim(implode(',', $ids_old_array), ',') . '"';
                             $post_content = str_replace($ids_old, $ids_new, $post->post_content);
                             wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content));
                         } else {
                             // $action = 'move'
                             $ids = explode(',', $pid);
                             foreach ($ids as $id) {
                                 if (in_array($id, $ids_old_array) == true) {
                                     $key = array_search($id, $ids_old_array);
                                     unset($ids_old_array[$key]);
                                 }
                             }
                             $ids_new_array = $this->upload_update_post($gallery, $ids_old_array);
                             $ids_new = 'ids="' . trim(implode(',', $ids_new_array), ',') . '"';
                             $post_content = str_replace($ids_old, $ids_new, $post->post_content);
                             wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content));
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:rainrose,项目名称:WoodsDev,代码行数:48,代码来源:wpmf-display-gallery.php


示例15: DNUI_getInfoImageFormPostsWithGallery

/**
 * Get all port with some gallery, this will help to show what image is used in some post, for the moment is only one notification
 * @global type $wpdb
 * @return type
 */
function DNUI_getInfoImageFormPostsWithGallery($without = false)
{
    global $wpdb;
    if ($without) {
        $sql = "SELECT id FROM " . $wpdb->prefix . "posts  WHERE  post_content is not null and post_content!=''  and post_type not in ('attachment','nav_menu_item','revision') and post_status !='draft' AND post_content LIKE '%[gallery%'; ";
    } else {
        $sql = "SELECT id FROM " . $wpdb->prefix . "posts  WHERE  post_content is not null and post_content!=''  and post_type not in ('attachment','nav_menu_item') and post_content LIKE '%[gallery%'";
    }
    //$sql = "SELECT id FROM " . $wpdb->prefix . "posts  WHERE post_content LIKE '%[gallery%' and post_type='post'; ";
    $result = $wpdb->get_results($sql, "ARRAY_A");
    $info = array();
    foreach ($result as $id) {
        $galleries = get_post_galleries($id['id'], false);
        foreach ($galleries as $gallery) {
            $idsImage = explode(',', $gallery['ids']);
            foreach ($idsImage as $idImage) {
                if (!array_key_exists($idImage, $info)) {
                    $info[$idImage] = array('sizes' => array());
                }
                $size = "original";
                if (array_key_exists('size', $gallery)) {
                    $size = $gallery['size'];
                }
                if (!in_array($size, $info[$idImage]['sizes'])) {
                    $info[$idImage]['sizes'][] = $size;
                }
            }
        }
    }
    return $info;
}
开发者ID:Wikipraca,项目名称:Wikipraca-WikiSquare,代码行数:36,代码来源:dnuiL.php


示例16: extract_images_from_galleries

 /**
  * Extract images in [galleries] shortcodes from text.
  *
  * @since 2.3.0
  *
  * @param string $richtext   Content to parse.
  * @param string $plaintext  Sanitized version of the content.
  * @param array  $extra_args Bespoke data for a particular extractor (optional).
  *
  * @return array
  */
 protected function extract_images_from_galleries($richtext, $plaintext, $extra_args = array())
 {
     if (!isset($extra_args['post']) || !is_a($extra_args['post'], 'WP_Post')) {
         $post = new WP_Post((object) array('post_content' => $richtext));
     } else {
         $post = $extra_args['post'];
     }
     // We're not using get_post_galleries_images() because it returns thumbnails; we want the original image.
     $galleries = get_post_galleries($post, false);
     $galleries_data = array();
     if (!empty($galleries)) {
         // Validate the size of the images requested.
         if (isset($extra_args['width'])) {
             // A width was specified but not a height, so calculate it assuming a 4:3 ratio.
             if (!isset($extra_args['height']) && ctype_digit($extra_args['width'])) {
                 $extra_args['height'] = round($extra_args['width'] / 4 * 3);
             }
             if (ctype_digit($extra_args['width'])) {
                 $image_size = array($extra_args['width'], $extra_args['height']);
             } else {
                 $image_size = $extra_args['width'];
                 // e.g. "thumb", "medium".
             }
         } else {
             $image_size = 'full';
         }
         /**
          * There are two variants of gallery shortcode.
          *
          * One kind specifies the image (post) IDs via an `ids` parameter.
          * The other gets the image IDs from post_type=attachment and post_parent=get_the_ID().
          */
         foreach ($galleries as $gallery_id => $gallery) {
             $data = array();
             $images = array();
             // Gallery ids= variant.
             if (isset($gallery['ids'])) {
                 $images = wp_parse_id_list($gallery['ids']);
                 // Gallery post_parent variant.
             } elseif (isset($extra_args['post'])) {
                 $images = wp_parse_id_list(get_children(array('fields' => 'ids', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_mime_type' => 'image', 'post_parent' => $extra_args['post']->ID, 'post_status' => 'inherit', 'post_type' => 'attachment')));
             }
             // Extract the data we need from each image in this gallery.
             foreach ($images as $image_id) {
                 $image = wp_get_attachment_image_src($image_id, $image_size);
                 $data[] = array('url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'gallery_id' => 1 + $gallery_id);
             }
             $galleries_data[] = $data;
         }
     }
     /**
      * Filters image galleries extracted from text.
      *
      * @since 2.3.0
      *
      * @param array  $galleries_data Galleries. See {@link BP_Media_Extractor::extract_images_from_galleries()}.
      * @param string $richtext       Content to parse.
      * @param string $plaintext      Copy of $richtext without any markup.
      * @param array  $extra_args     Bespoke data for a particular extractor.
      */
     return apply_filters('bp_media_extractor_galleries', $galleries_data, $richtext, $plaintext, $extra_args);
 }
开发者ID:mawilliamson,项目名称:wordpress,代码行数:73,代码来源:class-bp-media-extractor.php


示例17: twentyeleven_get_gallery_images

/**
 * Retrieve the IDs for images in a gallery.
 *
 * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
 *                            then as last option uses a get_posts() call.
 *
 * @since Twenty Eleven 1.6
 *
 * @return array List of image IDs from the post gallery.
 */
function twentyeleven_get_gallery_images()
{
    $images = array();
    if (function_exists('get_post_galleries')) {
        $galleries = get_post_galleries(get_the_ID(), false);
        if (isset($galleries[0]['ids'])) {
            $images = explode(',', $galleries[0]['ids']);
        }
    } else {
        $pattern = get_shortcode_regex();
        preg_match("/{$pattern}/s", get_the_content(), $match);
        $atts = shortcode_parse_atts($match[3]);
        if (isset($atts['ids'])) {
            $images = explode(',', $atts['ids']);
        }
    }
    if (!$images) {
        $images = get_posts(array('fields' => 'ids', 'numberposts' => 999, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment'));
    }
    return $images;
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:31,代码来源:functions.php


示例18: totomo_gallery_slider

/**
 * Display Gallery Slider
 *
 * @param integer $post_id get Id of singular
 * @param string  $thumbnail  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_post_galleries_images函数代码示例发布时间:2022-05-15
下一篇:
PHP get_post_format_strings函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap