Skip to content

Instantly share code, notes, and snippets.

@mwordpress
Created February 12, 2017 05:05
Show Gist options
  • Save mwordpress/d79a75f8ba0d49c74894a6b71d98b8ff to your computer and use it in GitHub Desktop.
Save mwordpress/d79a75f8ba0d49c74894a6b71d98b8ff to your computer and use it in GitHub Desktop.
the codes listed here is part of the following article : https://www.mwordpress.net/how-to-insert-thumbnail-to-woordpress-with-timthumb/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /media/
RewriteRule ^resizer/(.*)x(.*)/r/(.*) resizer/resize.php?src=http://sitename.com/wp-content/uploads/$3&h=$2&w=$1&zc=0&s=1
</IfModule>
<?php
function show_thumb($width, $height, $class, $postid, $quality) {
if ( has_post_thumbnail() ) {
$img = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full' );
$url = $img['0'];
echo '<img class="'.$class.'" src="'.home_url().'/media/resizer/'.$width.'x'.$height.'/r/'.remove_path($url).'" alt="'. get_the_title($postid).'" height="'.$height.'" width="'.$width.'" />';
}
}
function remove_path($url = ”) {
if ($url == 'http://' OR $url == 'https://'){
return $url;
}
$url = parse_url($url);
$url = explode('/', $url['path']);
$url = array_slice($url, -3, 3, false);
$url = $url['0'].'/'.$url['1'].'/'.$url['2'];
return $url;
}
?>
<?php
function show_thumb($width, $height, $class, $postid, $quality) {
if ( has_post_thumbnail() ) {
$img = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full' );
$url = $img['0'];
echo '<img class="'.$class.'" src="'.get_bloginfo('template_directory').'/resize.php?src='.$url.'&amp;w='.$width.'&amp;h='.$height.'&amp;zc=0&amp;s=1&amp;q='.$quality.'" alt="'. get_the_title($postid).'" height="'.$height.'" width="'.$width.'" />';
}
}
?>
// The Loop
while ( have_posts() ) : the_post();
?>
<div class="hentry">
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<div class="thumbnail">
<?php show_thumb(300, 150, ‘img-responsive’, $post->ID, 100); ?>
</div>
<p><?php the_content(”); ?></p>
</div>
<?php
endwhile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment