At the moment, I’m using featured images primarily, but have older posts which don’t have any. Because I have a section that show a random group of posts with images I decided to use catch_that_image in an if/else statement to make sure something showed up.
Now for featured images I have the following code
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150 ); }
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'article', 600, 250, true );
add_image_size( 'recent', 150, 70, true );
add_image_size('homepage', 200, 200, true);
add_image_size('slider', 400, 190, true);
So I really am hoping there is a way to use add_image_size or something similar to catch_that_image in order to do the 150×70 true option. I can set the size with html, but then it distorts the image pretty bad depending on original size.
Also here is my catch_that_image code and the code I’m using to call that or the featured image.
Catch_that_image code.
<?php
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/logo.png";
}
return $first_img;
}
?>
Code calling the images.
<?php
if ( has_post_thumbnail() ) { ?>
<p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'recent' ); ?></a></p>
<?php } else{ ?>
<p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"> <img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /></a></p>
<?php } ?>
I’ve tried just using the options from the add_image_size functions, but those don’t work, and I’ve tried different variations in the catch_that_image function as well.
I appreciate any help or insight anyone has.
]]>function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
if( get_field('bilder_bxslider') ):
while( has_sub_field('bilder_bxslider') ):
$first_img = the_sub_field('bildsnurra');
endwhile;
endif;
if(empty($first_img)) {
$first_img = bloginfo( 'template_url' ).'/images/default.jpg';
}
return $first_img;
}
]]>[ Moderator note: please wrap code or markup snippets in backticks or use the code button. ]
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
Please be good, I′m a Web Designer!:D
Thanks in advance!
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = get_bloginfo('template_directory') . '/images/noThumb.jpg"';
}
return $first_img;
}
Currently, I have to force the size of the image that is displayed by using CSS. Is there any way to change things so it uses the thumbnail sized image that I have defined? I figure that would drastically help reduce load times.
I have tried other methods of pulling the images, but I haven’t had the best luck. None of them were actually pulling images :/
]]>The site I am working on is www.theklean.com
My problem is that the theme doesn’t have an option to display just one photo in the preview. It’s either the entire post with all the photos or none at all. I found that a lot of people use catch_that_image to solve this problem but I can’t seem to get it to work. I have found quite a few post that describe how install it, but no matter what I keep getting error warnings, or it simply doesn’t work. I don’t know if there is something in the theme that is stopping it from working, or I’m just doing it wrong.
Any help or insight to this would be greatly appreciated.
]]>I am using the “catch_that_image()” function to pull out the first image of every post and display it as a Thumbnail (through Timthumb)
I am trying to figure out a way in which the function can be modified to pull out a random image from every post. [Instead of the first post, it should pull out a random image]
Since most of my posts will have atleast 25 images each, it would be great if the function can pull out a random image from these 25 to use as a thumbnail.
If an occasional post has less than 25 images and the function is unable to find the random image it is looking for, it should just show the first image as a default.
Please help me out
The “catch_that_image()” discussion is on this link:
https://www.ads-software.com/support/topic/retreive-first-image-from-post
I am using the “catch_that_image()” function to pull out the first image of every post and display it as a Thumbnail (through Timthumb)
I am trying to figure out a way in which the function can be modified to pull out a random image from every post. [Instead of the first post, it should pull out a random image]
Since most of my posts will have atleast 25 images each, it would be great if the function can pull out a random image from these 25 to use as a thumbnail.
If an occasional post has less than 25 images and the function is unable to find the random image it is looking for, it should just show the first image as a default.
Please help me out here
The “catch_that_image()” discussion is on this link:
https://www.ads-software.com/support/topic/retreive-first-image-from-post