function nice_image($args) { global $post; $width = null; $height = null; $class = ''; $quality = 90; $limit = 1; $offset = 0; $id = null; $echo = true; $is_auto_image = false; $src = ''; $meta = ''; $alignment = 'c'; $size = ''; $output = ''; if (!is_array($args)) { parse_str($args, $args); } extract($args); // set post ID if (empty($id)) { $id = $post->ID; } $thumb_id = get_post_thumbnail_id($id); // if empty, get standards if (empty($width) && empty($height)) { $width = get_option('thumbnail_size_w', '150'); $height = get_option('thumbnail_size_h', '150'); } if (!$src) { /* start searching for the image */ if (has_post_thumbnail($id)) { $src = get_nice_image_path($thumb_id); } else { // check the first attachment $attachments = get_children(array('post_parent' => $id, 'numberposts' => $limit, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); // Search for and get the post attachment if (!empty($attachments)) { // get first $src = get_nice_image_path(array_shift(array_values($attachments))->ID); } else { $matches = ''; $post = get_post($id); ob_start(); ob_end_clean(); $how_many = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { $src = $matches[1][0]; } } } } if (!empty($src)) { $output .= '<img src="' . get_template_directory_uri() . '/engine/timthumb.php?src=' . $src . '&w=' . $width . '&h=' . $height . '&q=' . $quality . '&a=' . $alignment . '" class="' . $class . '" />'; } if (nice_bool($echo)) { echo $output; } else { return $output; } }
<ul class="slides"> <?php if (get_post_meta($post->ID, 'embed', $single = true)) { ?> <li> <?php nice_embed('key=embed&width=610&wrap=true&embed_id=player_' . $post->ID) . "\n"; ?> </li> <?php } ?> <?php foreach ($attachments as $att_id => $attachment) { $src = get_nice_image_path($att_id); ?> <li> <?php if (has_post_thumbnail()) { ?> <?php echo nice_image('echo=0&width=610&class=wp-post-image&src=' . $src) . "\n"; ?> <?php } ?> </li> <?php
function nice_image($args) { global $post; global $nice_options; $width = null; $height = null; $class = ''; $quality = 90; $limit = 1; $offset = 0; $id = null; $echo = true; $is_auto_image = false; $src = ''; $meta = ''; $alignment = 'c'; $size = ''; $noheight = ''; // new vars. $alt = ''; $title = ''; $link = ''; $thumb_id = ''; $nice_timthumb_resize = true; /* deprecated */ $nice_wp_resize = false; if (!is_array($args)) { parse_str($args, $args); } extract($args); // Set post ID if (empty($id)) { $id = $post->ID; } // Get standard size, if not defined if (empty($width) && empty($height)) { $width = get_option('thumbnail_size_w', '150'); $height = get_option('thumbnail_size_h', '150'); } if ($src != '') { $src = esc_attr($src); } if (!$src) { /* start searching for the image */ // the ID is an attachment if (get_post_type($id) == 'attachment') { // get the data from the attachment $thumb_id = $id; $src = get_nice_image_path($id); // they send a post/page/cpt } elseif (has_post_thumbnail($id)) { $thumb_id = get_post_thumbnail_id($id); $src = get_nice_image_path($thumb_id); // they send nothing, get image from the content. } else { // check the first attachment $attachments = get_children(array('post_parent' => $id, 'numberposts' => $limit, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); // Search for and get the post attachment if (!empty($attachments)) { // get the first attachment. $thumb_id = get_post_thumbnail_id(array_shift(array_values($attachments))->ID); $src = get_nice_image_path(array_shift(array_values($attachments))->ID); } else { // retrieve the post content to find the first <img> appearance $matches = ''; $post = get_post($id); ob_start(); ob_end_clean(); $how_many = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { $src = $matches[1][0]; } } } } // OUTPUT $output = ''; // Image CSS class. if ($class) { $class = 'nice-image ' . esc_attr($class); } else { $class = 'nice-image'; } // Image metadata if ($thumb_id) { if ($alt == '') { $alt = esc_attr(get_post_meta($thumb_id, '_wp_attachment_image_alt', true)); } if ($title == '') { $title = esc_attr(get_the_title($thumb_id)); } } if (nice_bool(get_option('nice_wp_resize_crop'))) { $vt_crop = get_option('nice_wp_resize_crop'); // resize image if ($thumb_id) { // resize image $vt_image = vt_resize($thumb_id, '', $width, $height, $vt_crop); $src = $vt_image['url']; } elseif ($src) { $vt_image = vt_resize('', $src, $width, $height, $vt_crop); $src = $vt_image['url']; } } else { // use the thumbnail sizes if ($size) { $thumb_size = $size; } else { $thumb_size = array($width, $height); } // on the fly size //$img_link = get_the_post_thumbnail( $thumb_id, $thumb_size, array( 'class' => 'nice-image ' . esc_attr( $class ) ) ); $img_data = wp_get_attachment_image_src($thumb_id, $thumb_size); if (!empty($img_data)) { $src = $img_data[0]; } } // Start generating the output for the different resizing options. if (!empty($vt_image['url'])) { $output .= '<img src="' . esc_url($vt_image['url']) . '" class="' . $class . '" title="' . $title . '" alt="' . $alt . '" />'; } elseif (!empty($src)) { $set_width = ' width="' . esc_attr($width) . '" '; $set_height = ''; if (!$noheight && 0 < $height) { $set_height = ' height="' . esc_attr($height) . '" '; } // WP resize without cropping. $output .= '<img src="' . esc_url($src) . '" class="' . $class . '" title="' . $title . '" alt="' . $alt . '" ' . $set_width . ' ' . $set_height . ' />'; } if (nice_bool($echo)) { echo $output; } else { return $output; } }