I have developed this custom WP theme: http://www.asper-eritrea.com/
As you can see into the post excertpt (in the home page) it is showed the first immage into my posts.
To do it I use this code:
<div class="entry-content">
<?php
if (!has_post_thumbnail() && catch_that_image()) {
if ( get_the_post_thumbnail($post_id) != '' ) { // Se l'articolo non ha un'immagine predefinita:
echo '<span class="thumb"><a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
the_post_thumbnail();
echo '</a><span>';
} else {
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
echo '<img src="';
echo catch_that_image();
echo '" alt="" />';
echo '</a>';
}
}
?>
<?php
if(has_post_thumbnail()) {
echo '<span class="thumbnail"><a href="'; the_permalink(); echo '">';the_post_thumbnail(array(100,100)); echo '</a></span>';
}
?>
<?php the_excerpt(); ?>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
</div> <!-- .entry-content -->
To check if the *featured immage** existe I use the has_post_thumbnail() function that check if a post has an immage attached, then to retrieve this immage I use: the_post_thumbnail() function.
To retreive the first immage I use the custom function named catch_that_image() declared into my *functions.php** file, this one:
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)) {
$first_img = "/path/to/default.png";
}*/
return $first_img;
}
I want to have the following behavior: if in a post there is an immage but the featured immage is not setted then use the first immage in the post. If in the post there are more than on immage but the featured immage is setted then show the featured immage into the post excerpt.
In the functions.php file I also added the thumbnails support:
function aspertheme_setup() {
add_theme_support( 'post-thumbnails' );
}
Now my problem is that the first immage of a post is correctly shown but I can't set a featured immage because when I create a new post I have not the box for thumbnail setting.
Why? What am I missing? How can I solve this issue?
Tnx
Andrea
EDIT 1: Into the "Screen Options" tab at the top right of the page I only have this:
Did you checked in the dashboard the "Screen Options" tab at the top right of the page?
you are checking screen options directly in landing page of wordpress "Dashboard", don't check there, check inside posts or pages there you will find screen options including featured image, comments etc...