I’m using a photoblog theme which upon creating a new post it takes the post attachment and saves a modified “img src” string into the excerpt field. It then uses
<?php the_excerpt(); ?>
to display the thumbnail on pages like homepage menu, category pages and tag archives.
My website has a few hundred photos on it, and the theme isn’t retroactively creating the excerpt-based thumbnails for the old posts.
The developer is no longer officially supporting this theme, and after rifling through their support forum section, they even admitted “unfortunately, i donât know how to create old thumbnails.”– citation: http://everydays.hassii.com/archives/2541/comment-page-1#comment-9381
Here’s the bit of code they are using upon creating this excerpt thumbnail information on new/updated posts.
// ===== PB AUTO-INSERT EXCERPT ===== //
function pb_insert_excerpt(){
$post_data = &$_POST;
$post_id = $post_data['ID'] ;
$post_title = $post_data['post_title'];
$post_excerpt = $post_data['post_excerpt'];
$existing_img = strstr($post_excerpt, 'jpg');
if($post_data['post_excerpt'] = isset($post_data['excerpt'])) {
if ($existing_img) {
return $post_excerpt;
} else {
$arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post_id);
if($arrImages) {
$arrKeys = array_keys($arrImages);
$iNum = $arrKeys[0];
$sThumbUrl = wp_get_attachment_thumb_url($iNum);
$thumbWidth = get_option("thumbnail_size_w");
$thumbHeight = get_option("thumbnail_size_h");
$sImgString = '<img src="' . $sThumbUrl . '" width="'.$thumbWidth.'" height="'.$thumbHeight.'" alt="'.$post_title.'" title="'.$post_title.'" />' ;
return $sImgString;
}
}
}
}
add_filter('excerpt_save_pre', 'pb_insert_excerpt');
Using this same logic, is it possible to scan all old posts and create the excerpt img src thumbnail section?
Issue 1: creating the excerpt data
This should be fairly easy to do directly with SQL.
This is obviously a “one-time fix” that implies you have access to the database.
If the plug-in allows for more than one picture on one post and is using cover pictures to identify which of the pictures in the post’s gallery is the “default” used in the excerpt, then we need to extend the join clauses to check in wp_postmeta if the attachment is a cover picture or not.
Issue 2: updating the urls in the excerpt (from guid to thumbnail)
This should work only for JPG files, and it will apply the suffix of -100×100, replace in the suffix whatever dimensions you’re using. Provided that your dimensions are the same for all files.
If not we need a php script to read the postmeta data to accomplish this task.