Scan Article for First Image, or look for Custom Field (functions.php)
-
Scan Article for First Image, or look for Custom Field (functions.php)
Basically I have this in my functions.php
[code]
/* Catche First Image on Post
CURRENT: <?php echo catch_that_image() ?>
REPLACED: <?php get_thumb($post->ID, 'full'); ?>
*/
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;
}
[/code]
—-
and in my single.php, archive.php, index,php I have..
[code]
<img src="<?php bloginfo('template_directory'); ?>/includes/phpThumb/phpThumb.php?src=<?php echo catch_that_image() ?>&h=249&w=250&q=50&f=jpg&zc=1&sia=thenext2shine-<?php the_date('Y-m-d'); ?>
.jpg" alt="<?php the_title(); ?>" class="articleimage">
[/code]However I want to first check my CUSTOM FIELD “article_thumb” for the image.. and IF NOT.. then use the FIRST image in the article. How can I do this?
- The topic ‘Scan Article for First Image, or look for Custom Field (functions.php)’ is closed to new replies.