本文整理汇总了PHP中get_post_galleries函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_galleries函数的具体用法?PHP get_post_galleries怎么用?PHP get_post_galleries使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_galleries函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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');
}
示例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);
}
示例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;
}
示例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;
}
示例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">→</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
//.........这里部分代码省略.........
示例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">→</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-## -->
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
}
}
}
}
}
}
示例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;
}