Go Back    Forum > Digital Publishing / Web Sites > Website and Server Troubleshooting

Reply
 
LinkBack Thread Tools
  #1  
01-23-2011, 09:54 AM
kpmedia's Avatar
kpmedia kpmedia is offline
Site Staff | Web Hosting, Photo
 
Join Date: Feb 2004
Posts: 4,311
Thanked 374 Times in 341 Posts
As a long-time holder of a lifetime developer license of the Revolution/StudioPress Themes, almost from the very beginning, I've had access to many a great themes: Revolution, Revolution Two, StudioPress and now the Genesis framework set of themes. (If you've not used it, you really should, as they're better quality code-wise than any other theme available: www.studiopress.com. Easy-to-edit clean code work.) Anyway...

For quite a long time, Brian et al used the Tim Thumb (timthumb.php) for thumbnail generation, which wasn't always needed if we had already set our optimum thumbnail sizes in the WordPress 'Media' settings panel -- and we decided to use those site-wide. (Indeed, the only viable situation in which I can foresee valid use of timthumb is if you're planning to use varied image sizes all over a large site.) It was just extra code that could be removed.

To replace timthumb.php use in the theme, I simply commented out the old code and added in the new code. Here's my example from a new theme I created, based on a very stripped-down Revolution framework.

Full code that shows thumbnails and post excerpts on a "blog page" a.k.a. a WordPress page with post content:
Code:
<?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>

<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(); ?>" />

<div id="pptextbox">
<div id="pptitle"><h3><?php the_title(); ?></h3></div>
<div id="pptext"><?php the_content_limit(425, ""); ?></div>
<div id="pplink"><a href="<?php the_permalink() ?>"><?php _e("[Read More]"); ?></a></div>
</div>
<hr />
<?php endwhile; ?>
OLD timthumb code:
Code:
<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(); ?>" />
NEW non-timthumb thumbnail code:
Code:
<!--
<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(); ?>" />
-->

<div class="ppthumb">
<img src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" />
</div>
I like to comment out code, in case I want to change my mind later. I tend to not delete good code.

Now then, here timethumb.php made use of custom fields, with "thumb" as the field name. Well, the embedded use of WordPress can re-use the same variable name: "thumb". So I didn't have to change anything in my already-made posts.

Notice that my thumbnails are set to 160x160 size as shown in the above code. It's set that way in the Media options panel, too, in wp-admin.

And in case it's not obvious, all of the CSS is my own. You'll need entries for "ppthumb", "pptextbox", etc.

To make new posts, with proper thumbnail code, I would:
  • Upload the image to the post with the media/image manager/uploader built into WordPress,
  • Go ahead and "insert" the image into the post,
  • Click on the little "picture" icon that appears when you hover your mouse over the insert image,
  • Click over to the Advanced Settings tab, and then copy the Source of the image (example: xxxxxxxx_160x160.jpg)
  • 'X' the media box, because we're not changing anything,
  • And then scrolling down to the custom fields area of the post editor, and create a new custom field with "thumb" as the name and "hxxp://whatever.com/xxxxxxxx_160x160.jpg" as the value. (Note: Use http not hxxp in the URL. That was done to prevent auto-linking by this forum.)
  • Feel free to leave the image inserted in the post -- or even remove it entirely from the post. Yes, this means a thumbnail can be used on a post/page when the thumbnail itself doesn't even appear there!
This particular page loads much faster now, too, without the timthumb code.

Preview: (Note: Top image shows fixed code, bottom image shows what happened with timthumb usage)
timthumb-removed.jpg
Remember: You must be logged into the forum to view images/attachments. If you're not already a Free Member, then register now.


Why do this? Why replace timthumb on a site?

On one of the growing sites where I serve as a contributing editor, the heavy use of timthumb.php -- for what's essentially a minor aspect of the site design, i.e. showing thumbnails for posts on the homepage -- it slows the site down quite a bit. During peak hours (which is honestly just a mild amount of traffic), the site bogs down. And yes, it's cached with several plugins -- but remember that you don't really want to cache a homepage for very long, due to new content that appears there, so the cache is rebuilt frequently throughout the day. That's led us to look into various viable tim thumb replacements, or timthumb.php alternatives.

However that still wasn't my real reason for this post (and change that I made) ...

The site I had built worked perfectly on the digitalFAQ demo server, but simply would not work on the client's hosted account. PHP 5.2.13 and file system permissions were correct (tried both 777 and 755), but timthumb simply was not working. It was easier to replace it with WordPress base code. We had already limited thumbnail and image upload sizes in WP itself, so this added timthumb code was a waste of resources. To not work correctly was the nail in its coffin.

If this has helped you in any way, consider joining the forum (it's free!) and clicking the Thanks button. If this was as helpful as a magazine would have been, then donate a few dollars to our cause (helping people like you with digital media issues). Or feel free to leave a comment or ask questions on your WordPress theme needs.

Thanks.



- Did my advice help you? Then become a Premium Member and support this site.
- Please Like Us on Facebook | Follow Us on Twitter

- Need a good web host? Ask me for help! Get the shared, VPS, semi-dedicated, cloud, or reseller you need.
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
 
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
Reply




Tags
plugins, studiopress, timthumb.php, wordpress

Similar Threads
Thread Thread Starter Forum Replies Last Post
VHS Generation Loss, what it looks like over several generations NJRoadfan Restore, Filter, Improve Quality 1 12-23-2010 05:05 PM
Best USB thumb flash drive ? Sossity Blank Media 1 12-22-2010 03:56 AM
Autorun, malware, viruses, thumb drives, and Facebook games admin Computers 1 07-14-2010 02:22 AM
Replace your DVD Recorder Drive! Tom_n_Jonna Capture, Record, Transfer 5 02-08-2007 12:47 PM
Replace audio track ninjastriker Edit Video, Audio 2 07-11-2006 05:51 AM

Thread Tools



 
All times are GMT -5. The time now is 07:48 PM