Forum Moderators: coopster

Message Too Old, No Replies

Getting alt txt to display with timthumb

The thumbnail display but with a blank alt txt

         

cheaperholidays

8:03 am on Jul 17, 2012 (gmt 0)

10+ Year Member



Hi

I wonder if anyone can help, we have a thumbnails with timthumb that display the alt txt as alt="" when what we would like is the img title to be the alt txt.

So the current php is

<?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_url') .'/scripts/timthumb.php?zc=1&amp;w=80&amp;h=65&amp;src='); ?>

Have also tried, the code below, which cures the alt text issue but does not display the thumbnail.

<img src="<?php bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta(get_the_ID(), "thumb", $single = true); ?>&h=150&w=200&zc=1" alt="<?php the_title(); ?>" width="200" height="150" />

Any ides would be much appreciated.

Thanks for reading.

g1smd

8:17 am on Jul 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you talking about pop-up tooltip text on an image?

Use the 'title' attribute, not 'alt', for that.

The 'alt' text is for when the image fails to display.

That first bit of PHP doesn't directly generate the output HTML code. You need to look in the functions that are called.

cheaperholidays

8:38 am on Jul 17, 2012 (gmt 0)

10+ Year Member



Hi Thanks here are the functions

function get_post_image ($post_id=0, $width=0, $height=0, $img_script='') {
global $wpdb;
if($post_id > 0) {

// select the post content from the db

$sql = 'SELECT post_content FROM ' . $wpdb->posts . ' WHERE id = ' . $wpdb->escape($post_id);
$row = $wpdb->get_row($sql);
$the_content = $row->post_content;
if(strlen($the_content)) {

// use regex to find the src of the image

preg_match("/<img src\=('|\")(.*)('|\") .*( |)\/>/", $the_content, $matches);
if(!$matches) {
preg_match("/<img class\=\".*\" title\=\".*\" src\=('|\")(.*)('|\") .*( |)\/>/U", $the_content, $matches);
}
$the_image = '';
$the_image_src = $matches[2];
$frags = preg_split("/(\"|')/", $the_image_src);
if(count($frags)) {
$the_image_src = $frags[0];
}

// if src found, then create a new img tag

if(strlen($the_image_src)) {
if(strlen($img_script)) {

// if the src starts with http/https, then strip out server name

if(preg_match("/^(http(|s):\/\/)/", $the_image_src)) {
$the_image_src = preg_replace("/^(http(|s):\/\/)/", '', $the_image_src);
$frags = split("\/", $the_image_src);
array_shift($frags);
$the_image_src = '/' . join("/", $frags);
}
$the_image = '<img alt="" src="' . $img_script . $the_image_src . '" />';
}
else {
$the_image = '<img alt="" src="' . $the_image_src . '" width="' . $width . '" height="' . $height . '" />';
}
}
return $the_image;
}
}
}

cheaperholidays

8:41 am on Jul 18, 2012 (gmt 0)

10+ Year Member



Can no one help? It must be in the functions but where or how can i make the thumbnails have either the title="post title" or alt="post title" text displayed