Forum Moderators: coopster

Message Too Old, No Replies

need help with this php script and html

How to replace timthumb.php with wordpress thumbnail generation with php

         

tvirus

11:41 am on Sep 28, 2011 (gmt 0)

10+ Year Member



I want to replace the thumbnails generated by Timthumb script with wordpress static thumbnails.

i foud somewhere saying that i had toreplace this -
<img class="ppthumb" src="http://www.domain.com/wp-content/themes/%themename%/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", TRUE); ?>&amp;h=160&amp;w=160&amp;zc=0" alt="<?php the_title(); ?>" />


with this -
<img src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" />


But my theme's built-in_functions.php has this code -
if (count($data) > 0) {
$images .= '<h2>'.__('Photo Gallery','news').'</h2>';
$images .= '<div class="gallery-container">';
foreach($data as $k => $v) {
if ($v['alt'] && $v['title']) $alttext = $v['alt']; elseif ($v['title']) $alttext = $v['title']; else $alttext = $v['alt'];
$img_title = sprintf(__('%1$s (Photo %2$s of %3$s photo(s)).','news'), $alttext, ($k+1), count($data));
$images .= '<div class="gallery-item"><div class="fancybox-zoom"><a href="'.urldecode($v['src']).'" title="'.$img_title.'" class="zoomgallery" rel="gallery"><img src="'.get_bloginfo('template_directory').'/thumbopen.php?src='.$v['src'].'&amp;w=100&amp;h=100&amp;zc=1&amp;a=t&amp;q=100" alt="'.$img_title.'" title="'.$img_title.'" width="100" height="100" /><div class="zoom-black"></div><div class="zoom-overlay"></div></a></div></div>';
}
$images .= '<div class="clear"></div></div>'; // clear float fix
}


I replaced the IMG part with the code provided above and changed the path to reflect mine but i get this error - Unexpected T-String on line whatever

Please guide me...i'm totally new to PHP

g1smd

12:07 pm on Sep 28, 2011 (gmt 0)

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



There's a syntax error in the PHP, likely a missing semi-colon or bracket somewhere I expect.

Look at the line before the one flagged as being in error.

tvirus

12:22 pm on Sep 28, 2011 (gmt 0)

10+ Year Member



This is the line with the error. I already told that i'm new, i can't make out what's the error. Can you find out? :)
$images .= '<div class="gallery-item"><div class="fancybox-zoom"><a href="'.urldecode($v['src']).'" title="'.$img_title.'" class="zoomgallery" rel="gallery"><img src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" /><div class="zoom-black"></div><div class="zoom-overlay"></div></a></div></div>';

penders

1:25 pm on Sep 28, 2011 (gmt 0)

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



The problem seems to be that you are embedding PHP escapes (<?php ... ?>) inside the PHP string, and the single quotes are consequently messing things up and giving you the error.

So, it is easy enough to (hopefully) make it valid... by substituting this:
src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>"


With this, for instance...
src="'.get_post_meta($post->ID, 'thumb', true).'"


To become...

$images .= '<div class="gallery-item"><div class="fancybox-zoom"><a href="'.urldecode($v['src']).'" title="'.$img_title.'" class="zoomgallery" rel="gallery"><img src="'.get_post_meta($post->ID, 'thumb', true).'" alt="'.the_title().'" /><div class="zoom-black"></div><div class="zoom-overlay"></div></a></div></div>';


However, I'm not sure how this would work in the loop/theme? As this is just going to output the same src repeatedly?

Another thing that looks a bit dubious is this:
<img src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" />


By incorporating this into the loop, we assume that the_title() returns a string, but this bit of code implies the_title() echos the string directly - so this will not work inside the loop.

So, may be $img_title is required here instead:

$images .= '<div class="gallery-item"><div class="fancybox-zoom"><a href="'.urldecode($v['src']).'" title="'.$img_title.'" class="zoomgallery" rel="gallery"><img src="'.get_post_meta($post->ID, 'thumb', true).'" alt="'.$img_title.'" /><div class="zoom-black"></div><div class="zoom-overlay"></div></a></div></div>';


?

tvirus

7:24 am on Sep 29, 2011 (gmt 0)

10+ Year Member



The code you gave does not produce any error. however, images are not showing up :/
only alt is showing in place images.... i think i'll have to roam around wordpress codex. Thanks for the help anyways :)